Trying to get rid of a dc offset - tried other methods posted but to no avail

3 views (last 30 days)
I am applying the FFT function to data from an accelerometer and I have a large spike at 0Hz. I understand that this could be due to the DC offset. I have tried to subtract the mean from my data and apply a High pass filter, however, it doesnt get rid of the problem. Oh and I applied a hamming window, please see my code below. The only other thing I can think of is that I have not windowed my data or split it into sensible sections. Can this make a difference? At the moment I am using all of the data which included section where the patient group ran, walked and were involved in some everyday tasks.
clc
clear all;
x1=load('data.txt');
x=x1(:,1);
win = hamming(length(x));
win=ones(length(x),1);
y = (x-mean(x));
NFFT = 2.^nextpow2(length(x));
FFTX = fft(y,NFFT);
%FFTX = fft(y,NFFT)/length(x);
Fs=60;
figure(1)
%plotting
f = Fs/2*linspace(0,1,NFFT/2);
cyclespersecond=2*abs(FFTX(1:NFFT/2));
%applying a filter
z = cyclespersecond;
RC = (1/(2*pi*0.25));
dt = f(2) - f(1);%just check to see if 1/(NFFT/2)
alpha = (RC/(RC+dt));
n = length(z);
z2(1) = z(1);
for i= 2:n
z2(i)= (alpha * z2(i-1) + alpha * (z(i) - z(i-1)));
end
%note NFFT/2=1 has been changed to NFFT/2
%Plot single-sided amplitude spectrum.
plot(f,cyclespersecond) % only need to plot one half of the spectrum
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
figure (2)
plot(f,z2) % only need to plot one half of the spectrum
title('Single-Sided Amplitude Spectrum of y(t) with filter')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
  1 Comment
dpb
dpb on 19 Jan 2014
Take the mean off before applying the window for starters...there will be no DC component. That doesn't mean, of course, that there's not a bunch of very low frequency content in the data.
Also, you may get better idea of possible real data by using semilogy instead of linear y axis.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!