我想生成一些图表来说明使用傅立叶变换进行时间序列分析的缺点。我的目标是证明两个明显非常不同的信号具有非常相似的形状的光谱。首先,我创建了我的系列:
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');制作:

现在,我想展示它们的光谱具有非常相似的形状:

这些是一些课堂笔记中的例子,我想在matlab中重现。然而,我在重现第二个情节时遇到了困难。根据所提供的信息,谁能建议如何在matlab中生成第二个图?
发布于 2012-12-09 17:52:48
复制这些情节是相当容易的。但是,请注意以下几点:
t = 0到t = 4 (而不是像您做的那样是t = 2 )。这就是说,这是完整的代码(包括你的时域图的修复):
% # 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))时间域图是:

对应的频域曲线图为:

https://stackoverflow.com/questions/13786208
复制相似问题