如何绘制频谱图函数的结果?

6

在我的图形中,我有两个轴,第一个是信号的时间序列,第二个是信号的ifft。我想添加第三个轴,其中包含信号的频谱图。我该如何做?

% 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个回答

9
您需要在 spectrogram 中提供更多的输入参数。您所需的函数形式为:
[S,F,T]=spectrogram(x,window,noverlap,F,fs)

请参考http://www.mathworks.com/help/signal/ref/spectrogram.html的完整文档,但基本上需要定义以下内容:
  • windows:用于每个频谱估计计算的样本数
  • noverlap:从计算谱N-1中包含多少个样本到谱N中
  • 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函数的输入。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接