I would like to generate the spectrogram (power spectral density) from a temporal signal, having the frequency in Hz on the y-axis and time in seconds on the x-axis.
I have a sinusoidal signal generated like this:
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)
I plot the spectrogram / power spectral density as (p.s. I am not familiar with it):
fs = 1000/dt;
figure; spectrogram(x, [], [], [], fs, 'yaxis', 'psd')
I expected the plot to be Hz-vs-Seconds but I got kHz-vs-Seconds.
Also by setting fs=1/dt; the plot becomes Hz-vs-Hours.


ylimto be whatever you need. Please tell me if I'm missing something. - SecretAgentManylim([0, 0.012]),yticks(yticks*1000),ylabel('Frequency (Hz)')seems to work. But I am struggling to make the labels of the yticks visible. Do you know how to solve it? - Karl Alexius