Go Down

Topic: FFT Library for Arduino Due, SAM3X (Read 30766 times) previous topic - next topic

Magician

Mar 12, 2014, 01:27 am Last Edit: Jun 26, 2016, 11:07 pm by Magician

MarkT

There's a thread here for library listings, you might want to add that there.

Also what about a fast DCT next ;)
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Magician

Yes, I've seen one. Was hoping to get some feedback, before I post there .  If someone tested it on win/mac?
I also noticed, that timing results vary between 69xx and 71xx usec, and I can't see a reason. 

MarkT

Does the chip have a cache - that's a common reason for timing variability.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

pito

Quote
I also noticed, that timing results vary between 69xx and 71xx usec, and I can't see a reason.

The number of cycles for math calcs may depend on the actual operands values..

darko1979

#5
Jan 03, 2015, 04:20 pm Last Edit: Jan 03, 2015, 04:40 pm by darko1979
Hi Magician, First of all thank you for FFT Library for Arduino Due, SAM3X CPU !

I was planing to use example Arduino sketch FFT_ovSerMon_0.1d to run FFT for Signal of 500kHz.Well known for Arduino due is that ADC sampling rate is 1MSPS.

Title                          Arduino Due   II Arduino Due
MCK- Hz                   84,000,000   II 84,000,000
Prescaler                   2                               II 1
ADC Clock                   14,000,000        II 21,000,000
ADC Clock Cycle           20                               II 20
Sample Speed-Hz       700,000                       II 1,050,000
Freq. Range. Max- Hz 350,000                       II  525,000
Pockets                   2,048                       II 2,048
FFT Pockets           1,024                       II 1,024

After testing, results are OK if SMP_RATE is less than 600000UL ! My goal is to measure signal up to 500kHz. And for that I need to use prescaler 1 and #define   SMP_RATE       1000000UL  ! Please advice what changes are required to be done in example sketch? I have tried to change :
t->TC_CMR = TC_CMR_TCCLKS_TIMER_CLOCK5 |           // use TCLK5 (prescale by 1, TIMER_CLOCK5 input is equivalent to Master Clock), but no success!

Magician

#6
Jan 03, 2015, 05:19 pm Last Edit: Jan 03, 2015, 05:29 pm by Magician
Don't change Timer's prescaler, ADC is using it's own separate prescaler, and this line in adc_setup() defines it:
Code: [Select]
 adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);

 With ADC_FREQ_MAX prescaler sets to 6, that is the best integer divider of 84MHz to get close to 20MHz, according to data sheet max ADC clock. So ADC is running at 14MHz, and that's why you have ~600 ksps.
In order to get full speed, we have to violate data sheet prescription (slightly).
Change to:
Code: [Select]
 adc_init(ADC, SystemCoreClock, 21000000UL, ADC_STARTUP_FAST);

 I'm using next integer divider, 4, and to do trick send 21000000UL directly.
In my experience, arduino ADC can't reach exact 1MSPS, about 960 - 980 ksps at max, so define this line:
Code: [Select]
#define  SMP_RATE         960000UL

 no more, and only one input has to be active:
Code: [Select]
 adc_enable_channel(ADC, ADC_CHANNEL_7);      // AN0

In my last project
I have two inputs, with SPM_RATE 480000.

darko1979

#7
Jan 05, 2015, 07:44 pm Last Edit: Jan 05, 2015, 07:46 pm by darko1979
HI Magiciant , thanks for your help. For me all working  fine when:

#define  SMP_RATE         950000UL
adc_init(ADC, SystemCoreClock, 21000000UL, ADC_STARTUP_FAST);
adc_enable_channel(ADC, ADC_CHANNEL_7);      // AN0

I can run FFT now up to 475kHz which is OK for me!

vaclav


aslopez

Hi , i am kind of new with arduino and i would like to display in Processing software a graph of the fft of a signal (pre-amplified) that i am reading from a coil to my arduino, where i could show the different frequencies (from 500 Hz to 30 KHz).

Currently i am using Processing to show the signal and save the data in a file, then i open the file in MATLAB and then MATLAB process the FFT and graph the FFT and the signal.

Does someone know how i can calculate the FFT in my arduino DUE and display it in a Processing graph?


DAN_X

Hello Magiciant, your FFT Library for DUE is fantastic! I've spend the last 3 evenings to understand the FFT theme.
I'm following this forum since 2 years and learned a lot. But now I'm brave enough to ask something.

My frequency range to measure and to analyse is from 8kHz - 200kHz. I've taken your "FFT_SplitRRP_ovSerMon_1a.ino" example.
The only value I've altered was the sampling rate due to my frequency range.

#define   SMP_RATE        4800000UL

I've sampled some sine waves (array size 2048) and it was great to see results coming up with amazing speed.

Just to be sure about what I understand so far:
How can I calculate the effective frequency range (max) = SMP_RATE / 2 = 240kHz ?
And how do I calculate the frequency scale factor corresponding to the magnitude array position?
frequency scale factor = frequency range / out1[MIRROR] = 240kHz / 1024 = 0.234375 kHz (?)

But his is not matching up with my measurement results, what do I wrong?   

Magician

Thanks. 
It's a pity C language doesn't allow thousands separator, how many typo errors it could fix.
Quote
#define   SMP_RATE        4.800.000 UL
It's not what you expect?

DAN_X

Magiciant, thanks for your quick answer!
...and sorry for the typo, the right sample frequency is of course 480ks/s.

Meantime I've made some more tests and now everything fits perfectly.
A measured test sine of 20kHz is showing its magnitude peak at array position [86] and the corresponding calculation has a result of position [85].

This is pretty close, or do I have to ignore also position[0] while counting?

Magician

20.000 / 234.375= 85.33333  Your test freq. isn't the best choice, it doesn't fit well.  Main peak must be at bin = 85, with noticeable magnitude in sidelobes 84/86 and likely in 83/87. Do you have hamming ? W/o you'd have wider splash on both sides from 85 . Post your results

MarkT

I still wonder why people use an FFT when a DCT is all that's needed (faster, smaller)?

If you don't care about phase information, the DCT is the right choice, and factors of 2
or 4 in performance are really important on a microcontroller!
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up