Search code examples
signal-processingaccelerometerfft

FFT and accelerometer data: why am I getting this output?


I have read various posts here at StackOverflow regarding the execution of FFT on accelerometer data, but none of them helped me understand my problem.

I am executing this FFT implementation on my accelerometer data array in the following way:

int length = data.size();
double[] re = new double[256];
double[] im = new double[256];
for (int i = 0; i < length; i++) {
    input[i] = data[i];
}

FFT fft = new FFT(256);
fft.fft(re, im);

float outputData[] = new float[256];
for (int i = 0; i < 128; i++) {
    outputData[i] = (float) Math.sqrt(re[i] * re[i]
    + im[i] * im[i]);
}

I plotted the contents of outputData (left,) and also used R to perform the FFT on my data (right.) FFT

What am I doing wrong here? I am using the same code for executing the FFT that I see in other places.

EDIT: Following the advice of @PaulR to apply a windowing function, and the link provided by @BjornRoche (http://baumdevblog.blogspot.com.br/2010/11/butterworth-lowpass-filter-coefficients.html), I was able to solve my problem. The solution is pretty much what is described in that link. This is my graph now: https://i.sstatic.net/gNdag.jpg


Solution

  • The low frequency artefacts are probably due to a lack of windowing. Try applying a window function.

    The overall shift is probably due to different scaling factors in the two different FFT implementations - my guess is that you are seeing a shift of 24 dB which corresponds to a difference in scaling by a factor of 256.