使用 MATLAB spectrogram() 绘制频率 (Hz) 与时间(秒)
Using MATLAB spectrogram() to plot frequency (Hz) vs time (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)
我将频谱图/功率谱密度绘制为(p.s。我不熟悉它):
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
不是特别简洁,但应该可以。
我想从时间信号生成频谱图(功率谱密度),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)
我将频谱图/功率谱密度绘制为(p.s。我不熟悉它):
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
不是特别简洁,但应该可以。