Kanetsugu
Kanetsugu

Reputation: 27

FFT on accelerometer data spike at 0

I have some accelerometer data in MATLAB and I was told to try FFT and try to use FFT features on classification. However, I am confused about the plot after FFT. It seems that there is a large spike only in the beginning of the plot and I am not sure what to make of it. I tried using some code from other posts such as this one: Accelerometer with FFT - strange output, and also some examples on the Mathworks website, but it did not help.

data = acc_data_x(1:300);

fs = 1/(1/12);
m = length(data);
nfft = 2^nextpow2(m);
y = fft(data,nfft)/m;
f = fs/2 * linspace(0,1,nfft/2+1);
power = abs(y);
plot(f,power(1:nfft/2+1)) 
t = (0 : m-1)/fs;
figure
plot(t,data);

I attached the plot of the accelerometer data in x and the result of the FFT. Is there some other step I am missing? I apologize for any ignorance since this is my first time trying FFT and working with this type of data.

Accelerometer Data in X plot:

Accelerometer Data in X plot

After FFT:

After FFT

Edit: I have tried Gareth's suggestion and used detrend function in MATLAB

After Detrend and FFT:

After Detrend and FFT

Also here is the full data with FFT (in the first example I only used up to 300 data points).

Full Data Full Data with FFT

I'm now confused if this tells me any information?

Upvotes: 3

Views: 2496

Answers (2)

Sairus
Sairus

Reputation: 394

The amplitude of the first "zero-frequency" component in FFT is exactly the mean value of your data. If you fft(x-mean(x)), the first component will be zero. Other components nearby can be related with slow trend.

Upvotes: 0

Gareth Pulham
Gareth Pulham

Reputation: 654

You should first detrend your data. FFT inputs that have an uncorrected DC bias (ie, sits positive or negative) have a strong 0 Hz component.

Try data = detrend(data) after your first line. It'll skew some of the other things you do, but might help with showing the issue in the FFT. You can more carefully manage your data so that you can both clean it for FFT and also plot the original raw data once you feel happy with the issue being mostly fixed.

Upvotes: 3

Related Questions