matlab - 使用 MATLAB spectrogram() 绘制频率 (Hz) 与时间 (sec) 的关系图
问题描述
我想从时间信号中生成频谱图(功率谱密度),在 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。
解决方案
像上面一样执行您的代码,但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
不是特别简洁,但它应该可以完成这项工作。
推荐阅读
- angular - Ionic 4 - 打开模式时无法在离子搜索栏上书写
- spring - Spring Boot 不支持请求方法“GET”
- api - RPS:无法导入名称 ExporterIFCUtils
- python - 我正在使用 pyQT 构建桌面应用程序需要在没有 cmd 窗口提示的情况下弹出应用程序窗口
- java - 如何在同一活动中从一种布局切换回父布局
- javascript - Javascript不同的轮播具有相同的布局/样式
- java - Spring Boot中微服务暂时不可用时如何实现恢复机制?
- python - 由用户输入构建的嵌套字典
- docker - 无法使用 docker-compose 文件连接到 kafka-connect
- git - 跨不同 Git-TFS 分支的不同应用程序