Frequency resolution of Spectrogram

6 views (last 30 days)
Umer Khalid
Umer Khalid on 9 Jun 2016
Edited: Aabha on 9 May 2025
I have a signal sampled on 50Hz, i want to do spectrogram analysis of this signal.
the command
spectrogram(x,'yaxis')
this is working fine But the problem is that my band of interest is between 0 to 2 Hz, how can i change the resolution of my spectrogram to see that band of interest.
And also i would like to change the Y axis scale from bins to Hz

Answers (1)

Aabha
Aabha on 9 May 2025
Edited: Aabha on 9 May 2025
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.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!