I have a signal $a(t)$, this is how it looks when I plot it:

enter image description here

Zoom in enter image description here

I am trying to extract the eigenfrequencies of this signal using FFT in MATLAB. I do it like this

Y=fft( a(1:3:end) );

Fs = 1/1.5;       % Sampling frequency
T = 1/Fs;         % Sampling period
L = dms(2);       % Length of signal
t = (0:L-1)*T;    % Time vector

P2 = abs(Y/L);
P1 = P2(1:floor(L/2)+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f, P1)

Now, it turns out that if I use Y=fft( a ), I only get frequencies close to 0 when I plot the spectrum:

enter image description here

If I use Y=fft( a(1:3:end) ), then I get frequencies at 0 and nonzero frequencies:

enter image description here

  1. Why do these nonzero frequencies not appear when I do the FFT on the full dataset, but only when I sample every 4th point?
  2. Is the nonzero frequency actually contained in my dataset or is it an artifact?
  • 1
    $\begingroup$ you should add the sampling frequency you use and how exactly you're plotting this. $\endgroup$ – Marcus Müller Oct 16 '16 at 18:42
  • $\begingroup$ can you also add a zoomed in plot of your time domain signal? I really don't know what you're looking for in the spectrum at this point $\endgroup$ – Marcus Müller Oct 16 '16 at 18:47
  • $\begingroup$ I added a zoom-in as well. I'm trying to extract the oscillation-frequencies of the signal $\endgroup$ – BillyJean Oct 16 '16 at 18:50
  • $\begingroup$ can you zoom in more? $\endgroup$ – Marcus Müller Oct 16 '16 at 18:53
  • 1
    $\begingroup$ uh-oh. you undersampled. See my answer's edit. $\endgroup$ – Marcus Müller Oct 16 '16 at 20:48

If I use Y=fft( a(1:3:end) ), then I get frequencies at 0 and nonzero frequencies:

Well, yes, but that means you decimate your signal by a factor of 3, which on one hand will shift frequencies to $\frac13$ of their original frequency, but also will lead to aliasing. In other words: unless you know there's no signal above $f=\frac16f_\text{sample}$, you simply can't do that.

EDIT (based on zoomed-in plots):

So, hand-counted from your most-zoomed in plot, it seems there's about 5 peaks in 20 samples, which implies a period of 4 samples. That is ok by Nyquist's sampling theorem.

Now, if you just look at every third sample, which you do by doing a(1:3:end), then there's only ~1.333 samples per period. Nyquist demands that there's at least 2 samples per period. So, your second attempt aliases the signal from the $\frac15f_\text{sample/2}$ onto a different point in the spectrum, where it actually isn't. You damaged your signal by undersampling; you mustn't do that. It's not very clear to me how the idea to do that happened in the first place, but you should definitely read up on the Sampling Theorem.

  • $\begingroup$ I added the sampling frequency etc. to my code in the OP $\endgroup$ – BillyJean Oct 16 '16 at 18:45
  • $\begingroup$ Thanks, that is a very useful comment. I will have to read up more on this important topic. $\endgroup$ – BillyJean Oct 17 '16 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.