1

I am working on a pedometer application and I am running a real-time fft on accelerometer data where I use the arduinoFFT (kosme) library on an Arduino 101.

So let's say my sampling frequency is at 100Hz. I am interested in the up an down motion of the body which matches walking or running frequencies at around 1-4Hz. Many of the libraries including the one I am using seem to have a compute magnitude function. This effectively gives me half the number of bins used number of amplitudes (if I was inputting 64 samples, it will give me 32 amplitudes).

So my question is what frequencies does these amplitudes correspond to? In the example code the library provides, the frequencies are calculated as follows:

for (int i=0; i<(noofbins>>1); i++) {
  freq[i]=((i*samplingfreq)/(noofbins>>1));
}

I truly do not understand why this is the case and please excuse me if I am being completely silly about it. Furthermore, this indeed gives me frequencies from 0 to 100Hz (the sampling frequency I use). Is there any way of refining the fft about the frequency of interest without lowering the sampling frequency to 'match' it (which would be a terrible idea here)?

thephysicsguy
  • 403
  • 1
  • 4
  • 15
  • 1
    Possible duplicate of [How do I obtain the frequencies of each value in an FFT?](http://stackoverflow.com/questions/4364823/how-do-i-obtain-the-frequencies-of-each-value-in-an-fft) – Paul R Mar 19 '17 at 21:52
  • Each FFT bin has a resolution of `Fs / N = 100 / 64 = 1.5625 Hz` in your case - so bin index 3 will correspond to a frequency of `3 * 1.5625 = 4.6875 Hz` - see [linked duplicate answer](http://stackoverflow.com/a/4371627/253056) for more details. – Paul R Mar 19 '17 at 21:53

1 Answers1

1

what frequencies does these amplitudes correspond to?

I'm not sure exactly where you got that example, and why it would be dividing by noofbins>>1. The correct formula for the frequencies of each bins is given by:

for (int i=0; i<(noofbins>>1); i++) {
  freq[i]=((i*samplingfreq)/noofbins);
}

This will give you frequencies from 0 to the Nyquist frequency (half of the sampling frequency). In your specific case, that would be from 0 to 50Hz (in increments of 100/64 = 1.5625Hz).

Is there any way of refining the fft about the frequency of interest without lowering the sampling frequency [...]?

Capturing more data, that is increasing the number of samples used as input to the FFT, will result in a better frequency resolution of the FFT. For example, using 128 samples (slightly more than 1 second worth of data) instead of 64, would bring the frequency increments from 1.5625Hz down to 0.78125Hz. Further increasing the number of samples to 256 (about 2.5 seconds) would reduce the frequency increment to ~0.39Hz.

SleuthEye
  • 14,379
  • 2
  • 32
  • 61
  • Yes that makes a lot of sense. All I need to do then is feed in more data although I still have from 10Hz till 50Hz unused. Would it be wise to cut down sampling frequency down to 10Hz and wait for enough data to arrive to fill in eg:128 bins? Couldn't I then chop up the 100Hz samples into 10 bunch of 10Hz samples anyway? – thephysicsguy Mar 19 '17 at 22:40
  • 1
    If your signal doesn't contain any energy above 5Hz, you could indeed reduce the sampling frequency down to 10Hz. But waiting for the same duration (say 1s) will result in the same frequency resolution (though you would save on processing). As far as chopping the 100Hz samples into 10 bunch at 10Hz, you could do that provided that your signal doesn't contain energy above 5Hz but what would that give you? – SleuthEye Mar 20 '17 at 00:32