如何绘制光谱图功能的结果?

时间:2012-12-13 11:25:03

标签: matlab spectrogram

在我的图中我有2个轴,第一个是信号的时间序列,第二个是信号的ifft。我想添加一个包含信号频谱图的第3轴。我怎么能这样做?

% Create the raw signal
fs = 40;
t = 0:( 1/fs ):4;
y1 = [ sin( 2*pi*5*t( t<=2 ) ), sin( 2*pi*10*t( t>2 ) ) ];

% Compute the ifft of the signal
Fy1 = abs(ifft(y1));
N = numel(t);
idx = 1:numel(Fy1) / 2;
f = fs*(0:(N-1)) / N;

% Plot the raw signal as a time series
subplot(311);
plot(t,y1,'k');
xlabel('Time (s)');
ylabel('Amplitude');

% Plot the spectrum of the signal
subplot(312);
plot(f(idx),2*Fy1(idx),'k')
xlabel('Frequency (cycles/second)');
ylabel('Amplitude');

我尝试过使用spectrogram函数但是我很难将结果解释为数字。如何计算频谱图,以便沿着x轴运行时间和y?

的幅度

1 个答案:

答案 0 :(得分:6)

您需要在spectrogram中提供更多输入参数。您需要的功能形式是:

[S,F,T]=spectrogram(x,window,noverlap,F,fs)

请参阅http://www.mathworks.com/help/signal/ref/spectrogram.html完整文档,但基本上您需要定义:

  • windows:用于每次频谱估算计算的样本数
  • noverlap:在频谱N
  • 中计算频谱N-1需要包含多少个样本
  • F:您想要在
  • 评估频谱的频率
  • fs:信号的采样频率。

然后使用以下符号绘制频谱图:

subplot(313);
imagesc( T, F, log(S) ); %plot the log spectrum
set(gca,'YDir', 'normal'); % flip the Y Axis so lower frequencies are at the bottom

注意:频谱图的质量可解释性取决于在spectrogram函数中使用正确的输入。

相关问题