Shop OBEX P1 Docs P2 Docs Learn Events
Fast Hartley transform (interactive demo included) — Parallax Forums

Fast Hartley transform (interactive demo included)

Andrey DemenevAndrey Demenev Posts: 377
edited 2014-12-30 14:03 in Propeller 1
What: Fast Hartley transform. I am not going to write math here. In simple words, Harley transform converts from time domain to frequency domain. Hartley transform of finite discrete data (for example, electrical signal sampled with analog-to-digital convertor) is called Discrete Hartley Transform. Direct computation of Discrete Hartley Transform takes much time. An algorithm allowing to significantly reduce calculation time is called Fast Hartley Transform. Other similar transforms exist (Sine, Cosine, Fourier, etc), each with their own properties. Fourier transform is best known and most used for spectral analysis. In many cases, Hartley transform can be used instead of Fourier transform. In general, Hartley transform takest 2 times less memory and roughly 2 times less time compared to Fourier transform, because Fourier transform operates on complex numbers, and Hartley transform - on real numbers. Though, there exist fast Fourier transform algorithms working with real numbers.

Why: just for fun :) First practical use coming to mind is audio spectrum analyzer.

How: "standard" in-place radix-2 decimation-in-time fast Hartley transform. The code was translated almost 1:1 from C++ source by J

Comments

  • nglordinglordi Posts: 114
    edited 2011-09-03 17:45
    Andrey; If you search for Fast Hartley Transform you will find that I have posted FHT versions in spin, pasm, and propforth on this forum.

    NickL
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2011-09-03 19:23
    Nick, yes, I did see your posts and the code. Sorry, of course, I should mention your work. But the code posted here has more features, offers a better interface, and is faster.
  • nglordinglordi Posts: 114
    edited 2011-09-03 21:09
    Andrey: Your interface is far superior to my approach. Using pasm for conversion of fht to fft is a big advantage. I have not been able to try Demo-FHT. I get an error message:
    "Object exceeds runtime memory limit by 123 longs."

    Nick
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2011-09-03 21:27
    Nick, use BST (or PZST) with optimizations on to compile the demo. Even after optimizations, there are only 20 longs free for SPIN stack. I'll add this information to the first post
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-09-03 22:28
    Andrey Demenev,

    Great DEMO!

    Since you don't need to double buffer the video in this demo, you can save half of the display memory AND load it from the Propeller IDE if you change a couple lines in the CON block so that they read...
    _stack = ($3000 + 60) >> 2
    

    and
        bitmap_base = $3000
        display_base = $3000
    
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2011-09-03 23:51
    Since you don't need to double buffer the video in this demo

    Well, I could make it without double buffering, but display update is too slow, and fliccker is visible. The better way would be to reduce amount memory used by display.
    Attached is a modified demo using less display tiles, should fit the memory without optimization. First post has been updated accordingly
  • potatoheadpotatohead Posts: 10,261
    edited 2011-09-04 11:30
    You could potentially trade frame rate for the double buffer. See my blog here:

    http://forums.parallax.com/entry.php?86-Ripple-Draw

    For the frame rate trade, simply do not present the display with new data, until all the strips have been drawn. Frame rates possible, depend on 60Hz or 50Hz divided by the number of strips chosen for the display.

    You can also trade image integrity, allowing "tearing", by still drawing the strips in the same way, while allowing new data. That is the technique shown in the videos.

    Both can be done either with a small partial buffer (recommended), or no buffer at all, if the draw speed is quick enough. For the no-buffer approach, there is a more advanced method, where the clearing of the draw strip is done incrementally, isolating flicker zones to small parts of the active strip, not shown. If you are interested in that, let me know. IMHO, the video for the single buffer was a bit aggressive, with some flicker to be seen. That illustrates the draw speed limits in action, as significant flicker can be seen in the time consuming objects, and not so much at all with the fast ones.

    Finally, a sweep works for some images well, and not others. The strips can be interleaved, to eliminate the "sweep" effect seen in both videos, or the frame rate trade-off with no new data can be done to minimize, and in some cases, completely eliminate the sweeping motion.

    Great demo! I can't wait to run this. A read earlier in my blog might explain some of why. Thanks for your explanation that filled a gap for me.
  • nglordinglordi Posts: 114
    edited 2011-09-10 18:54
    Andrey:

    After comparing your FHT version with my pasm version, I have concluded that a major contributor to the significant dfferences in spreed is the handing of dsin/dcos. Your approach uses the sin table in the prop chip while my algorithm calculates updated values which involves 4 multiplications per cycle.

    I have made some modifications in your fht.spin to conform to the syntax of my applications as well as include some additional functions {see attached fhtm.spin), especially Convolve & Autocorrelate. I have also attached another demo (MakingWaves) which is the inverse of your demo, although not as elegant.

    NickL
  • Andrey DemenevAndrey Demenev Posts: 377
    edited 2011-09-11 07:35
    Nick, thanks. That is great contrubution. I am now adding window functions (few standard predefined, and arbitrary thru external tabble). When this is done, we'll see if FFT, correlation and convolution can be fitted into assembler code for speed.

    Also, I have been experimenting with another Fourier-related transform - constant-Q transform. Fourier and Hartley transforms have linear frequency resolution. This makes them not very well suited for audio analysis. Human auditory system has high resolution at low frequencies, and the resolution decreases with frequency increase. Fourier transform provides redundant resolution at higher frequencies, but too low resolution at lower frequencies. Instead of analyzing equally spaced narrow bands (as in FT), CQT can analyze frequency bands with (reasonably) arbitrary center frequencies and bandwidths. Later I'll post results of my experiments with this transform
  • HemPeterHemPeter Posts: 28
    edited 2012-01-03 10:23
    Hi Guys,
    I just found this thread and I'm excited about the prospect of higher frequency resolution at audible frequencies.
    I'm trying to make an audio tuner for my dissertation, and I've been playing around with the FFT that Beau posted a while back.
    I stumbled on the video of the Constant-Q transform and I was mightily impressed.
    I was wondering if there was any progress made and advice that could be given to a budding young propeller enthusiast? =)
    Cheers
  • sebastian1989sebastian1989 Posts: 14
    edited 2014-12-30 14:03
    Hello, I am using your code in a project where I need to get a FHT from a signal, I add a spi RAM (23lc1024 1Mbit) and a ADC (MAX1168 16bit 200Ksamp/s) all this in the same cog, with the new library I read N samples from the ADC and write directly in the RAM, then I make the FHT in the RAM.
    Now the problem, I need the FHT from 16384 data points but doesn't work well, can anyone help me? I dont understand completly how your code work, I am new in PASM (and english XD).
    If I reduce the data points to 8192 all works nice.

    The image show the problem, It's like aliasing but it is not.
    The clock output in my code is for a low pass filter, I use a MAX293 (8th order low pass filter with a variable cutoff frecuency, "electronics witchcraft")

    "serial fht.spin" is an example.
    "matserial.m" is a script to receive data from serial and plot in matlab.
Sign In or Register to comment.