0
votes

I am new to Matlab and FFT.
I need to extract the dominant frequency from a signal which is varying in magnitude and frequency. I tried to perform a detrend and then an FFT to obtain the frequency but couldn't get rid of the large peak at 0Hz (DC component?). I used diff function on the signal and the resulting signal was processed through FFT. In this case, the FFT output didn't have the peak at zero. I compared the two FFT curves and it seems that except the peak at zero, the two show similar (not same) spectrum. I am wondering if diff function is a valid (and very effective) detrending method or am I losing some information here? In other words, does differentiating a signal have any effect on its frequency: [diff(sin(omega.t))= cos(omega.t) - no change in frequency]?

Thanks a lot!

2
I am guessing that you differentiate the signal because when you differentiate any function the constant or 0Hz component dissapears. Also take ito account that FFT is not the ideal fourier transform (but it is the one used), so that slight different in the spectrum may come from there.Ander Biguri

2 Answers

2
votes

By differentiating the signal you actually apply a a type of a highpass filter, a not so smart highpass which corrupts your signal. Instead you could try some other filter such as the following:

b=fir1(32,2*0.01/fs,'high');
a=1;
FilteredX=filtfilt(x,a,b)

where:

x is your original signal,

FilteredX is the filtered signal.

fs - your sample frequency.

This way you will filter out any frequencies lower then 0.01 and will almost not hurt the rest of the spectrum allowing you to detect peaks as you wished.

1
votes

The discrete fourier transform X of a signal x is defined (up to scaling) by

X(k) = Sum[ exp(2*pi*i*k*n/N) * x(n) ]

If we take first differences of the signal you get

Sum[ exp(2*pi*i*k*n/N) * (x(n) - x(n-1)) ]

which you can rearrange to give

(1 - exp(2*pi*i*k/N)) * Sum[ exp(2*pi*i*k*n/N) * x(n) ]

i.e. it is a multiple of the original fourier transform. In the k = 0 case (i.e. the zero frequency component) the multiplier is zero, which explains why this removes the spike at k = 0.

Note however that the multiplier depends on the value of k, so you won't get the same signal out - you can't just take first differences to remove a spike. There is a comparison to be made with the continuous fourier transform, where if g = F(f) and h = F(df/dx) then

h(k) = i * k * g(k)

i.e. the fourier transform of the derivative is the fourier transform of the original function, multiplied by ik.