
Offline
Jr. Member
Karma: 0
Posts: 63


« Reply #1 on: April 23, 2012, 02:56:45 am » 
thanks pete, it's very usefull



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #2 on: April 23, 2012, 11:27:22 am » 
Thank you.
Pete



Logged





Gijon  Spain
Offline
Newbie
Karma: 0
Posts: 23


« Reply #3 on: May 22, 2012, 05:50:35 am » 
Looks great, thanks



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #4 on: May 22, 2012, 04:17:37 pm » 
You're welcome.
Pete



Logged





California
Offline
Newbie
Karma: 0
Posts: 12


« Reply #5 on: August 01, 2012, 09:47:06 pm » 
If you are interested in using FFT for a real world application, have a look at the ATmega328Accuracy project, at http://sourceforge.net/projects/lxardoscope/files/accuracyInvestigation/ . In this project, FFT was used with sinewaves for characterization of the ATmega328 ADC. Results include SignaltoNoise Ratio and Effective Number of Bits.



Logged





NYC
Offline
Full Member
Karma: 0
Posts: 129
The singularity is near!


« Reply #6 on: August 11, 2012, 09:59:00 am » 
Is this for making an FM transmitter? What is FFT used for?



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #7 on: August 11, 2012, 10:36:05 am » 
The Fast Fourier Transform is a mathematical technique to analyze the frequency components of a signal.
Pete



Logged





Offline
Newbie
Karma: 0
Posts: 28


« Reply #8 on: July 04, 2013, 07:26:15 pm » 
Hi, peter, thank you for linking me to your post. ( http://forum.arduino.cc/index.php?topic=175679.15) I still don't understand why the way I generate sine wave data is not correct. Can you explain how you generate useful data to test fft please? I was using "k = 127*sin(2*3.14 * 100 * t )" to generate the data, 100 = wave frequency, but someone asked me what my simulated sampling frequency is, I have no idea what it is, or how to set it. I wanted to simulate it as if I'm take the data out of A0 from an oscilloscope at a sampling rate of 38.5 khz . I don't have access to an socilloscope right now, but even if I do, I think it's better to simulate it with pure data first. Thank you



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #9 on: July 04, 2013, 08:09:32 pm » 
k = 127*sin(2*3.14 * 100 * t ) The problem is with the values of t that you use. The basic formula is, as you have it there, A*sin(2*3.14 * f * t) where A is amplitude, f is the frequency in Hertz, and t is in seconds. But in your loop the values of t are 0, 1, 2, 3 etc. So your code is "sampling" the 100Hz sine wave once every second  i.e. at t=0 seconds, then t=1 second, etc. To sample the sine wave at, say, 1000Hz you would need to generate samples for t = 0, .001, .002, .003 etc. which would require that t be a floating point value and increment it by .001 each time through the loop. For a simulated sampling rate of 38.5kHz you would need to increment t by .000025974. With 256 samples you will be generating the equivalent of 6.65ms. BTW, I don't know how sensitive the FFT will be to numerical errors but I would suggest that you use a more precise value for pi. use 127*sin(2*PI*100*t) Pete



Logged





Offline
Newbie
Karma: 0
Posts: 28


« Reply #10 on: July 05, 2013, 06:13:43 pm » 
k = 127*sin(2*3.14 * 100 * t ) The problem is with the values of t that you use. The basic formula is, as you have it there, A*sin(2*3.14 * f * t) where A is amplitude, f is the frequency in Hertz, and t is in seconds. But in your loop the values of t are 0, 1, 2, 3 etc. So your code is "sampling" the 100Hz sine wave once every second  i.e. at t=0 seconds, then t=1 second, etc. To sample the sine wave at, say, 1000Hz you would need to generate samples for t = 0, .001, .002, .003 etc. which would require that t be a floating point value and increment it by .001 each time through the loop. For a simulated sampling rate of 38.5kHz you would need to increment t by .000025974. With 256 samples you will be generating the equivalent of 6.65ms. BTW, I don't know how sensitive the FFT will be to numerical errors but I would suggest that you use a more precise value for pi. use 127*sin(2*PI*100*t) Pete Hey, Pete: Great explanation! Thank you so much.



Logged





Offline
Newbie
Karma: 0
Posts: 28


« Reply #11 on: July 05, 2013, 07:16:23 pm » 
Hi, pete,
It worked! Thank you.
When I tried to to have A =1 from "k = A*sin(2*3.14159 * 100 * t / 400 )", every bin is zero. When I used large A,I was able to see much larger numbers in the bins where the frequency closest to. I still have a lot of other numbers in other bins. Is that normal to FFT? I can set a limit and filter out these numbers, but I wanna make sure I'm using FFT correctly.



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #12 on: July 05, 2013, 08:20:36 pm » 
The sine function has values between plus one and minus one so if you set A=1, all your samples will be small values. With a clean signal you should still be able to pick out the tone but it is a lot easier when the amplitude is larger. I still have a lot of other numbers in other bins. Is that normal to FFT? You have exhausted what I know about the FFT :) You can get noise in the resulting signal but it should be significantly lower than the tone you're looking for. I also get strange results with some signals and I haven't been able to figure out why it happens. Pete



Logged





Offline
Edison Member
Karma: 48
Posts: 1636


« Reply #13 on: July 05, 2013, 08:44:21 pm » 
if you set A=1, all your samples will be small values More to the point, if you are using the same library as I am, the samples are all 8bit integers so if A=1 the only values you would be giving the FFT would be 1, 0 and +1 which would result in a very noisy signal! Pete



Logged





Rapa Nui
Offline
Edison Member
Karma: 60
Posts: 2073
Pukao hats cleaning services


« Reply #14 on: July 07, 2013, 09:39:37 am » 
When you use integer values, for example 0..1023 with 512 points fft you may use: f=20; //frequency for (i=0; i<512; i++) { k[i] = 1023*sin(2*pi*f*i/511); } As the result you shall see a frequency in the bin n. 20 with an amplitude of aprox 511 (where in bin n. 0 is DC). You will see of course some data in other bins as well. That is normal. When sampling real data you have to be aware of aliasing, and you need to apply a "windowing" function before doing the fft (Hamming, Hann(ing), Blackman, and 20 others  in order to eliminate the effect of the sampling window). By using the windowing function the "shape" of the spectral lines (ie your n.20) changes  you will see less noise around the particular spectral line. http://en.wikipedia.org/wiki/Window_functionPS: Corrected


« Last Edit: July 09, 2013, 03:45:20 pm by pito »

Logged





