如何绘制频谱图函数的结果? [英] How can I plot the results of the spectrogram function?

查看:295
本文介绍了如何绘制频谱图函数的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的图中,我有2个轴,第一个是信号的时间序列,第二个是信号的ifft.我想添加一个第三轴,其中包含信号的频谱图.我该怎么办?

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. I'd like to add a 3rd axes that contains the spectrogram of the signal. 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');

我尝试使用spectrogram函数,但是我很难将其结果解释为数字.如何计算频谱图,以便我有时间沿x轴运行,而振幅沿y轴运行?

I've tried using the spectrogram function however I'm having a hard time interpreting its results as a figure. How do I compute the spectrogram so that i have time running along the xaxis and the amplitude along the y?

推荐答案

您需要向spectrogram提供更多输入参数.您需要的功能形式为:

You need to provide more input arguments into spectrogram. The form of the function you need is:

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

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

See http://www.mathworks.com/help/signal/ref/spectrogram.html complete documentation, but basically you need define:

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

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

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

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

Note: The quality and interpretability of a spectrogram depends on using the correct inputs into the spectrogram function.

这篇关于如何绘制频谱图函数的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆