Fast Hartley Transform
ngl
Posts: 24
·· There has been some discussion of the Fast Fourier Transform implementation on the propeller in another thread on this forum.· One approach was detailed in the Propeller Wiki. I would suggest that a more practical approach to fft implementation is the Fast Hartley Transform (FHT), which works with real numbers,·therefore·running faster than the FFT. Furthermore, the FHT is its own inverse function and the FFT can be calculated from the FHT. Ullmann (sepwww.stanford.edu/theses/sep38/38_29_abs ) has described a FHT algorithm (expressed in Ratfor) which is easily translated·into Spin.
·· The attached spin file is a first implementation of·the 1-dimensional HFT, which also includes methods for calculating the Power Spectrum and the FFT. ViewPort was used to debug the program and view the results.· Things to do include providing a graphical data display, converting the subroutines (eg, butterfly) to pasm, timing studies with larger data sets,·and implementing·the 2-dimensional FHT.
Comments and suggestions are welcome.
Nick
Corrected spin file and url.
New attachments include updated FHT object, Functions.spin, Utilities.spin, Demo1 & Demo2.spin.
Post Edited (ngl) : 12/6/2009 2:11:07 AM GMT
·· The attached spin file is a first implementation of·the 1-dimensional HFT, which also includes methods for calculating the Power Spectrum and the FFT. ViewPort was used to debug the program and view the results.· Things to do include providing a graphical data display, converting the subroutines (eg, butterfly) to pasm, timing studies with larger data sets,·and implementing·the 2-dimensional FHT.
Comments and suggestions are welcome.
Nick
Corrected spin file and url.
New attachments include updated FHT object, Functions.spin, Utilities.spin, Demo1 & Demo2.spin.
Post Edited (ngl) : 12/6/2009 2:11:07 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Regards, David
Post Edited (Drone) : 10/30/2009 12:13:52 PM GMT
·
I am very interested in this work. My problem is that I don't know much about FFT or FHT, but having this code and references gives me somewhere to start. I am looking forward to your successes at getting it into ASM, as well as tests of timing.
Jim C.
(And nice use of ViewPort!) Got any screenshots? Any chance you could apply this to my "Speech Recognition" challenge?
Hanno
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Co-author of the official Propeller Guide- available at Amazon
Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
12Blocks, the block-based programming environment (thread here)
and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer
Hanno: ViewPort allowed me to quickly find programming errors. A great product. I will have to look at the speech recognition challange.
I would like to use the xy widget in ViewPort to display the FHT results. Any hints on how to do this?
There is a sign error in the FFT method. The last statement should be Im[noparse][[/noparse]k] := (-fx[noparse][[/noparse]k] + fx[noparse][[/noparse]len-k+2])/2
I have converted the program to a true object which also includes convolution & correlation methods. I will post as soon as I have a working demo.
Thanks! The xy widget takes the values of two traces at the current timescale and plots them in xy fashion. Not sure what you want to do, but typically you would share at least 2 variables, select the proper timescale, and plot 2 channels.
Hanno
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Co-author of the official Propeller Guide- available at Amazon
Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
12Blocks, the block-based programming environment (thread here)
and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer
This is very cool. I don't have a copy of viewport (yet), so I made a version that uses the Parallax Serial Terminal. I set up the output so it can be directly imported into PLX_DAQ for easy plot/visualization. I also added sin, cos, step, and impulse functions to the examples you had so I could see the output with various waveform inputs.
I included a copy of my PLX_DAQ excel file in the archive...for anybody who'd rather get a fresh copy of PLX_DAQ, it is available here:
http://www.parallax.com/Portals/0/Downloads/sw/plx_daq_install.zip
The output from the various input waveforms isn't exactly what I was expecting...but that may be as much due to my ignorance of the subject area as anything else. Between you, Jay, and lonesock, and others, it's been a veritable frequency transform cornucopia here in the forums lately.
Looking forward to your next update.
BR
EDIT: updated archive attachment:
-Added a random (white) noise function, pulse function
-Added a simple measurement of #clock cycles required to complete H-xform
-Added magnitude and phase plots in excel PLX_DAQ worksheet
-Misc. tweaks
Post Edited (BR) : 11/2/2009 3:19:54 AM GMT
BR:· Thanks for your interest and additions to FHT. I have incorporated them, with modifications to accomodate the new FHT object, in the attached demo program.· That is, your earlier additions.· I look forward to making further additions to the demo program.
I have replaced attached programs with new versions containg BR's latest additions.
Nick
Post Edited (ngl) : 11/3/2009 2:07:22 AM GMT
None the less, it looks like an interesting alternative to the typical FFT.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
The code works in that I could reproduce all Bracewell's examples that I tried.
Nick
I also cross-checked the FFT methgod using the Descrete Fourier Transform in Mathematica.
Post Edited (ngl) : 11/3/2009 6:22:52 AM GMT
I'm hoping I can squeeze the algorithm into 240 instructions, leaving 256 registers for the element array, which would speed things up slightly (and make the bit reversal permutation trivial as it would happen on the load from HUB to COG). Moving the data out to HUB RAM means the array could be any size, but the elements would have to be LONGs. (Probably 16+16 signed fixed point.)
And what sample data do people use? 8 bit signed or unsigned, 16 bit signed, or some fixed point? The output is always signed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
@ericball: as to sample data, 16 bit signed seems to be a good fit for the prop. cessnapilot has been proponing a "Qs15_16" fixed point format (http://forums.parallax.com/showthread.php?p=829958). I've been pondering what it would take to implement this for a digital filter project I've been experimenting with. Might be worth considering for your Bracewell algorithm, assuming you decide to put the data in the hub ram.
Using HUB RAM also opens the possibility of having multiple cogs process the data simultaneously. There would need to be some mutual synchronization to ensure each stage is completed before the cogs start the next stage. But other than that, the algorithm parallelizes quite nicely.
Note: the scaling should be 1/sqrt(N) so the transform is it's own inverse. In my algorithm I'm going to shift the result as a part of every other stage, which should help with overflow.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
edit 2009-11-12
It turns out the FHT starts doing the 4 element butterfly after two rounds of 2 element add/sub transforms. I didn't realize it until I started executing the third round by hand and discovering it didn't match the expected results. Then I went back through the patent and paid more attention to the initial theory section. Unfortunately, this makes the FHT more complex, the inner loop is now 364 cycles per sample, so around 21.5 1024 sample FHTs per second. (That's a minimum rate, actual may be slightly faster.)
I also discovered a bunch of problems with my math routines - signed values are a little trickier to handle than unsigned values.
I'm editing this to note my errors & progress (hopefully) without bumping the topic to the top.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Composite NTSC sprite driver: Forum
NTSC & PAL driver templates: ObEx Forum
OnePinTVText driver: ObEx Forum
Post Edited (ericball) : 11/13/2009 1:10:34 AM GMT
The demos are structured to allow the user to select specific examples as well as· which datasets to plot.
The following approximate times in milliseconds were recorded for the FHT as a function of data sequence lengths: 8 -> 3, 16 -> 6, 32 -> 15,
64 -> 34, and 128 -> 77.·· Convolution of two datasets measured 24 msec for 16 and 257 msec for 128 member arrays.
Nick
I guess you've got a couple monitors available to you in your setup (one for viewing pst output and one for the VGA plot output from the demo board). I found Kye's driver on obex and am able to see your plot output. As an FYI, if you select "File/Archive/Project..." in the propeller tool, it will automatically kick out a nice zip archive containing everything needed for someone else to run the demo. Archives are easier to attach to forum posts, too.
I have edited the first post to include the current versions of all FHT files.
This FHT version runs about 20x faster ( 16 member sequence - 0.27 msec compared to 6 msec) than the spin version. Since this is
my first attempt at serious pasm programming, I would appreciate any comments regarding possible improvements.
Nick