2

I am analyzing accelerometer data through FFT as it was suggested that I get information on frequency from the output of FFT. How is the output of FFT correlated with frequency information.

The FFT function is passed an array of values (all real numbers). The FFT function gives back 2 arrays of the same size - for the real and complex part.

I read up some of the previous posts and still confused as to how you can extract the frequency information from the output array of FFT. 1. Is the output array an array of frequencies? Is the array ordered? 1. What does each index of the output array mean? It was suggested that you can compute the magnitude of each index - sort (real[i]* real[i] + img[i] * img[i]) 2. Is the magnitude at each index somehow related to the index in the input array - or is this a frequency? 3. How do I find the dominant frequency?

1 Answers1

5

FFT gives you a complex pair in each Frequency Bin. The first bin in the FFT is like the DC part of your signal (0 Hz), the second bin is Fs / N, where Fs is the sample rate and N is the windowsize of the FFT, next bin is 2 * Fs / N and so on. To get the Power contained in a bin you will need the magnitude. As for the dominant freqency: that is the highest peak in magnitude.

ben
  • 1,380
  • 9
  • 14
  • Thanks a lot! Makes a lot of sense. – user3096748 Feb 24 '14 at 19:35
  • One thing I noticed is that when I get the output, and compute the magnitude of each bin - its mirrored around the mid-point. So if my window size is 256 - 0 is the DC value (huge spike which I ignore).1 and 255 has same value, 2 and 254 have same value, 3 and 253 have same value. Is that common? – user3096748 Feb 24 '14 at 19:39
  • My question is : if its indeed mirrored then should I calculate frequency with N or N/2. So second bin is FS/(N/2)? – user3096748 Feb 24 '14 at 20:49
  • 1
    No, the second bin is still FS/N. The spectrum has first the frequencies FS*k/N for k=0,1,...,N/2-1, i.e., from 0 to about FS/2, and then wraps around to the negative part of the spectrum from -FS/2 to 0 with frequencies FS*(k-N)/N, k=N/2,...,N-1. The fftshift function exchanges both halfs so that the frequencies are from -FS/2 to FS/2 monotonically increasing. For real signals the negative part is a mirror image of the positive, so you can just as well leave it out. – Lutz Lehmann Feb 25 '14 at 00:14
  • I am using the FFT code that is specified under http://stackoverflow.com/questions/9272232/fft-library-in-android-sdk?rq=1 . Does that seem correct? Thanks so much. – user3096748 Feb 25 '14 at 19:12
  • Hi - Also does the sample rate can be any rate? Basically number of cycles per seconds or minutes. Does it need to be in Hertz? – user3096748 Feb 26 '14 at 21:36
  • your signal has a rate in which new values get sampled, that is the samplerate, most commenly in Hz. If you do a FFT of that signal and you wish to use another freqency you will have to resample (downsample or interpolate) it. And Hertz is defined as 1/sec so it is basicly the only thing I can think of which is able to express a sample rate. – ben Feb 27 '14 at 07:11
  • If I am trying to measure shaking through android accelerometer readings - its not as sensitive to use Hertz as units. It may make sense to have a larger unit like per minute? – user3096748 Feb 27 '14 at 07:22
  • well that would be Hz too, there are such things as 0.01666... Hz (~ 1/60 Hz, one period per minute) – ben Feb 27 '14 at 07:28
  • and there is one more thing you should be aware of: The FFT shows you frequencies contained in your signal. If you go down in your samplerate, you are not able to detect freqencies above fs/2 any more. So you should think of what you are looking for: Short high freqency bursts, like a shock to the sensor or something(impulse or step in the time domain) which has low freqencys, like breathing or something like that (slow periodics in time domain). For more information (in better english) refere to [The Scientist and Engineer's Guide to DSP](http://www.dspguide.com/pdfbook.htm) – ben Feb 27 '14 at 07:42
  • I see. So you are saying that FFT is not a good solution for signals that have a low frequencies - like 4 times in a second. Can FFT not be extend to apply in this case by defining the sample rate as just the number of cycles per minute? I am indeed looking for the short frequency bursts. – user3096748 Feb 27 '14 at 19:52
  • what I trying to say is that the FFT has its strong points in finding periodic elements in a signal, which are then represented as energy in frequency-bins. A Impulse (like a dirac-impulse) or Step in the time domain is repressentet as a rise in alot frequencies in the frequency domain, because it needs alot frequencies to "build" such a impulse/step, so it is detectable via FFT. And if a element in the signal repeats every 0.01 sec you will see a peak at 100Hz, so you can do it via FFT, but surely there are other methods out there. – ben Feb 28 '14 at 07:28
  • And the units for cycles per minute is something like `(number of something happening) / (time it happend in)` which sounds a lot like `how often per time unit does it happen?` which can be answerd by saying `120 times a minute` or `twice a secound`. That is 2 Hz(`2* 1/s`) or 120 cpm (`120 * 1/min`). So the "Unit" for expressing how often something happens in a time periode can always be expressed as Hz or cpm since they are stating the same, just with a different "base time frame". That means all you have to do for FFT to give you another multiply the results to match your unit of choice. – ben Feb 28 '14 at 07:39