简体   繁体   English

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

[英]How can I plot the results of the spectrogram function?

Within my figure I have 2 axes, the first is the time series of the signal and the second is the ifft of the signal. 在我的图中我有2个轴,第一个是信号的时间序列,第二个是信号的ifft I'd like to add a 3rd axes that contains the spectrogram of the signal. 我想添加一个包含信号频谱图的第3轴。 How can I do this? 我怎样才能做到这一点?

% 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');

I've tried using the spectrogram function however I'm having a hard time interpreting its results as a figure. 我已经尝试过使用spectrogram功能但是我很难将其结果解释为数字。 How do I compute the spectrogram so that i have time running along the xaxis and the amplitude along the y? 如何计算频谱图,以便沿着x轴运行时间和沿y运行的幅度?

You need to provide more input arguments into spectrogram . 您需要在spectrogram提供更多输入参数。 The form of the function you need is: 您需要的功能形式是:

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

See http://www.mathworks.com/help/signal/ref/spectrogram.html complete documentation, but basically you need define: 请参阅http://www.mathworks.com/help/signal/ref/spectrogram.html完整文档,但基本上您需要定义:

  • windows : the number of samples to use for each spectral estimate calculation windows :用于每个频谱估计计算的样本数
  • noverlap : how many samples to include from the calculation of spectrum N-1 in spectrum N noverlap :从频谱N中的频谱N-1的计算中包括多少个样本
  • F : the frequencies you want the spectrum evaluated at F :您希望频谱评估的频率
  • fs : the sampling frequency of your signal. fs :信号的采样频率。

Then plot the spectrogram with: 然后绘制谱图:

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

Note : The quality and interpretability of a spectrogram depends on using the correct inputs into the spectrogram function. 注意 :频谱图的质量和可解释性取决于在spectrogram功能中使用正确的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM