FFT and accelerometer data: why am I getting this

2019-02-20 17:38发布

问题:

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

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: http://imgur.com/wGs43

回答1:

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.



回答2:

Because all your data on left are above 0, for frequency analyze it is a DC signal. So after your fft, it abstract the DC signal out, it is very hugh. For your scene, you only need to cut off the DC signal, just preserve the signal over 0 Hz(AC signal), that makes sense.