The ‘spectogram’ function has a few optional arguments that can be used to modify the resolution of the spectogram. The argument ‘window’ refers to the size of the window and is specified as a positive integer or as a row or column vector. It is used to divide the signal into segments and affects the time-frequency resolution trade-off. The window size can be increased for better frequency resolution and decreased for better time resolution. Additionally, you can also specify the sample rate ‘fs’. It represents the number of samples per unit time. However, fs must be the fifth input to the ‘spectrogram’ function. To input a sample rate and still use the default values of the preceding optional arguments, specify these arguments as empty (‘[]’). Once you specify the sample rate, the units of the y-axis will automatically change to ‘Hz’ instead of ‘bins’.
Here is an example code for the same:
N = 1024;
n = 0:N-1;
w0 = 2*pi/5;
x = sin(w0*n)+10*sin(2*w0*n); % Example signal
Fs = 50; % Sample Rate
window = hamming(256); % Adjust window size for better resolution
noverlap = round(length(window)*0.75); % 75 percent overlap
nfft = 512; % Increase for better frequency resolution
spectrogram(x, window, noverlap, nfft, Fs, 'yaxis');
ylim([0 2]) % Set y-axis limit to 0-2 Hz
Please refer to the following MathWorks documentation link for more information about the 'spectogram' function:
I hope this helps.


