Change ylim of spectogram

10 ビュー (過去 30 日間)
Dominik Deml
Dominik Deml 2023 年 6 月 10 日
コメント済み: Simon Chan 2023 年 6 月 10 日
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 Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by