Pregunta

I would like to generate some figures to show the disadvantages of using Fourier transforms for time series analysis. I aim to show that 2 apparently very distinct signals have a spectra with very similar shape. To begin I create my series:

t =  0:.01:2;
y = sin(2.*pi.*5.*t)+sin(2.*pi.*10.*t);
r1 = find(t <= 1);
r2 = find(t > 1);
y2a =  sin(2.*pi.*5.*t(r1));
y2b = sin(2.*pi.*10.*t(r2));
y2 = [y2a,y2b];

figure(1);
subplot(211);
plot(t,y,'k');
subplot(212);
plot(t,y2,'k');

Producing: enter image description here

Now, I would like to show that their spectra have very similar shapes: enter image description here

These are examples taken from some class notes that I would like to reproduce in matlab. However, I am having difficulties in reproducing the second plot. Could anyone suggest how the second plot can be produced in matlab with the information provided?

¿Fue útil?

Solución

Reproducing those plots is fairly easy. However, note several things:

  1. In your class notes, the time domain plots are from t = 0 to t = 4 (not t = 2 like you did).
  2. The frequency domain plots show only the positive frequencies, i.e. half the frequency spectrum. The frequency range is from 0 to 20Hz, meaning that the sampling frequency is 40Hz.
  3. The amount of energy must remain the same, so if only half the spectrum is displayed, the plotted frequency components should be multiplied by a factor of 2.

That said, here's the complete code (including fixes to your time domain plots):

% # Time domain plots
fs = 40;
t = 0:(1 / fs):4;
y1 = sin(2 * pi * 5 * t)+ sin(2 * pi * 10 * t);
y2 = [sin(2 * pi * 5 * t(t <= 2)), sin(2 * pi * 10 * t(t > 2))];

figure
subplot(2, 1, 1), plot(t, y1)
subplot(2, 1, 2), plot(t, y2)

% # Frequency domain plots
Fy1 = abs(ifft(y1));
Fy2 = abs(ifft(y2));
N = numel(t);
idx = 1:numel(Fy1) / 2;    % # Indices of half the spectrum
f = fs * (0:(N - 1)) / N;  % # Actual frequencies

figure
subplot(2, 1, 1), plot(f(idx), 2 * Fy1(idx))
subplot(2, 1, 2), plot(f(idx), 2 * Fy2(idx))

The time domain plots are:

enter image description here

and the corresponding frequency domain plots are:

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top