Effacer les filtres
Effacer les filtres

Change ylim of spectogram

2 vues (au cours des 30 derniers jours)
Dominik Deml
Dominik Deml le 10 Juin 2023
Commenté : Simon Chan le 10 Juin 2023
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.

Réponse acceptée

Simon Chan
Simon Chan le 10 Juin 2023
Modifié(e) : Simon Chan le 10 Juin 2023
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 commentaires
Dominik Deml
Dominik Deml le 10 Juin 2023
Thank you! Can you explain me why?
Simon Chan
Simon Chan le 10 Juin 2023
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Language Fundamentals dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by