Change ylim of spectogram

2 次查看(过去 30 天)
I'd like to change the `ylim` (frequency) values of my spectogram plot.
fs = 20000;
n = 0:5*fs - 1;
N = length(n);
t = n/fs;
fT = 1000;
fM = 3;
delta_phiT = 10;
uFM = 1*cos(2*pi*fT*t + delta_phiT*sin(2*pi*fM*t));
spectrogram(uFM, 1024, 256, 4096, fs, 'yaxis');
What I tried so far:
ylim([800 1200]);
But after doing this the spectogram is empty.

采纳的回答

Simon Chan
Simon Chan 2023-6-10
编辑:Simon Chan 2023-6-10
It should divide by 1000.
fs = 20000;
n = 0:5*fs - 1;
N = length(n);
t = n/fs;
fT = 1000;
fM = 3;
delta_phiT = 10;
uFM = 1*cos(2*pi*fT*t + delta_phiT*sin(2*pi*fM*t));
spectrogram(uFM, 1024, 256, 4096, fs, 'yaxis');
ylim([800 1200]/1000); % Divide by 1000
  2 个评论
Dominik Deml
Dominik Deml 2023-6-10
Thank you! Can you explain me why?
Simon Chan
Simon Chan 2023-6-10
Here is the original code:
fs = 20000;
n = 0:5*fs - 1;
N = length(n);
t = n/fs;
fT = 1000;
fM = 3;
delta_phiT = 10;
uFM = 1*cos(2*pi*fT*t + delta_phiT*sin(2*pi*fM*t));
spectrogram(uFM, 1024, 256, 4096, fs, 'yaxis');
After that, you can extract the axis information as follows and it shows that the y-limit is from -0.0024 to 10.0024, but not something from -0.0024 to 10,002.4.
On the other hand, the ylabel in the above figure shows that the unit is in kHz instead of Hz and hence you need to divide the freqency in Hz by 1000 in this case.
ax=gca
ax =
Axes with properties: XLim: [0.0064 4.9600] YLim: [-0.0024 10.0024] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.1164 0.1100 0.6937 0.8150] Units: 'normalized' Show all properties

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by