FFT on AVR

jboavida
 
Avatar
 
Subject:

FFT on AVR

 · 
Posted: 05.11.2010 - 14:03  ·  #1
Hi all,

I have a project that reads a K-Band radar sensor for traffic speed measurment. The frequency of the signal is related to the speed of the car. Samplig must be done @ 8 to 10khz (256 points).
Most designs use FFT to get the fundamental frequency (wich gives the correct speed).

As anyone implement something like it on AVRCO ? It there any lib or algoritm for this?
I don't even know if AVR as the power to do this.

I know that Microchip (and is dsPIC devices) had a FFT library avaiable, but I really don't want to use Pics and C...


Thanks

Joaquim
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1408
Registered: 03 / 2005
Subject:

Re: FFT on AVR

 · 
Posted: 05.11.2010 - 17:07  ·  #2
Hi Joaquim.

This could be difficult. The dsPIC is a (sort of) DSP device (the AVR is not). Depending an the accuracy required of your samples, sampling rates could be as low as 15k samples per second for example with a MEGA1280, so not far off the limits of your needs. (Additional warning - the data sheet says 'up to' so you may have to ve very careful, using interrupt processing etc. to achieve that). Processing will hit you hard too, with less than 1500 machine instructions per sample at 16 MHz, which sounds a lot, but for FFT using Pascal and with various overheads, it really is not.

I wish you luck with your endeavours.

Merlin.
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: FFT on AVR

 · 
Posted: 05.11.2010 - 18:54  ·  #3
jboavida
 
Avatar
 
Subject:

Re: FFT on AVR

 · 
Posted: 05.11.2010 - 23:11  ·  #4
Thanks Merlin and Avra for your comments.

I think that Chan's algorithm (which is made in assembler) maybe enough for my needs.
Unfortunately I don't have the skills to integrated Chan's source in AVRCO.

I will give it a try in AVR-GCC. Maybe someone has the time to do it. It will be a great addiction to AVRCO, since it is freeware code.

http://elm-chan.org/works/akilcd/report_e.html
Look for avrfft.zip

Thanks. I will post the results later.

Joaquim
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: FFT on AVR

 · 
Posted: 07.11.2010 - 13:20  ·  #5
Let's take a look at Pascal path for a second, just one more time... As I could see, Chan's code is just implementation mixture of fixed point numbers and FFT. You already have fix32 fixed point numbers in AvrCo, and if I remember well you also have square root and basic trigonometric functions in the source. So you just need to implement FFT. You can try implementing FFT on your own, but I have seen around some Pascal FFT code that uses floating point numbers (Google is your friend, but be careful and read licenses well). You should just use fixed point numbers instead of floating point numbers in the code, so that part is solved. Also Chan's code is well commented so even without knowing ASM you can recode FFT in Pascal from scratch, by just looking at comment that explain the math behind the code. Whatever. Then, when you have working code and measure your performance, you can do necessary optimizations. You will probably want to improve calculation speed, and two things come first to my mind. First is implementing fix16 instead of fix32 (you have full commented source of the fix32 library here) by using fix16 s7.8 which is actually fixed 7 bits + 1 sign bit for integer part and fixed 8 bits for fractional part (fixing this improves calculation speed dramatically - this is why fix64 in AvrCo has s31.32), and second is by making lookup table for trigonometric functions. You could use this Chan's table for comparison:
Code
; 16bit fixed-point FFT performance with MegaAVRs
; (Running at 16MHz/internal SRAM)
;
;  Points:   Input, Execute,  Output,    Total:  Throughput
;   64pts:   .17ms,   2.0ms,   1.2ms,    3.4ms:   19.0kpps
;  128pts:   .33ms,   4.6ms,   2.4ms,    7.3ms:   17.5kpps
;  256pts:   .66ms,  10.4ms,   4.9ms,   15.9ms:   16.1kpps
;  512pts:   1.3ms,  23.2ms,   9.7ms,   34.2ms:   14.9kpps
; 1024pts:   2.7ms,  51.7ms,  19.4ms,   73.7ms:   13.9kpps

Of course, speed heavily depends on how many FFT points you have in your goal. Just a guess, but with very low number of points and above mentioned optimizations implemented, you might even save your self from ASM.
jboavida
 
Avatar
 
Subject:

Re: FFT on AVR

 · 
Posted: 07.11.2010 - 18:16  ·  #6
Avra,
The calculation performance using 16bit FP seems to be enough. The problem may be on getting the samples (in this case 256) using mega128 ADC. AFAIK, the maximum sample rate at maximum resolution will be 15Ksps, wich limits the sampled frequency to 7.5Khz (Nyquist).
This will be on border line if what I need. Maybe the solution is to change to the Xmega. 32Mhz and 1,5uS conversion time on the ADC.
Using the Xmegas, maybe I can just use pascal only, anf forget asm. What do you think?

Joaquim
Avra
Schreiberling
Avatar
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: FFT on AVR

 · 
Posted: 08.11.2010 - 11:14  ·  #7
Huh, 256 is not a low number of points. Anyway, I haven't touched XMEGA yet so only experiment can tell...
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   110   124 · Page-Gen-Time: 0.062955s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI