1
votes

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)?

1
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 for more details.Paul R

1 Answers

1
votes

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.