【问题标题】:Using MATLAB spectrogram() to plot frequency (Hz) vs time (sec)使用 MATLAB spectrogram() 绘制频率 (Hz) 与时间 (sec) 的关系图
【发布时间】:2019-12-03 12:05:43
【问题描述】:

我想从时间信号生成频谱图(功率谱密度),y 轴上的频率以 Hz 为单位,x 轴上的时间以秒为单位。

我有一个像这样生成的正弦信号:

dt = 0.04; % Integration time step in ms
T = 10000;  % simulation time in ms -> so 10 seconds of simulation
nt = round(T/dt); % simulation steps

x = sin(2*pi*frequency*(1:1:nt)*dt/1000 + phase);
figure; plot((1:1:nt)*dt/1000, x)

我将频谱图/功率谱密度绘制为(ps我不熟悉):

fs = 1000/dt;
figure; spectrogram(x, [], [], [], fs, 'yaxis', 'psd')

我希望情节是 Hz-vs-Seconds,但我得到的是 kHz-vs-Seconds。 也可以通过设置fs=1/dt;情节变为 Hz-vs-Hours。

【问题讨论】:

  • 如果你想要 Hz,你能把 yTicks 重新标记为 1000 倍吗?然后你就有了 Hz 并且可以将 ylim 更改为你需要的任何东西。如果我遗漏了什么,请告诉我。
  • 谢谢@SecretAgentMan,使用ylim([0, 0.012])yticks(yticks*1000)ylabel('Frequency (Hz)') 似乎有效。但我正在努力使 yticks 的标签可见。你知道怎么解决吗?

标签: matlab time-series spectrogram


【解决方案1】:

像上面一样执行您的代码,但不要使用yticks(yticks*1000),而是执行以下操作:

% Get yRuler-object
ax = gca;
yRuler = ax.YAxis;

% Loop through TickValues, multiply and insert into TickLabels cell-array
for n = 1:numel(yRuler.TickValues)
    yRuler.TickLabels{n} = num2str(yRuler.TickValues(n) * 1000);
end

不是特别简洁,但它应该可以完成工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 2019-06-09
    • 2017-02-04
    • 1970-01-01
    • 2020-01-21
    • 2016-09-21
    • 2014-07-15
    相关资源
    最近更新 更多