How to understand spectrogram function
707 views (last 30 days)
Mark Golberg on 31 Jan 2016
Hello, can someone explain please (in plain english as much as possible) what's the difference between:
1) [s,w,t] = spectrogram(x,window,noverlap,w) returns the spectrogram at the normalized frequencies specified in w.
2) [s,f,t] = spectrogram(x,window,noverlap,f,fs) returns the spectrogram at the cyclical frequencies specified in f.
maybe someone can provide a simple example.
Vidya Viswanathan on 4 Feb 2016
The primary difference between the two is in the way the input signal is specified. In the first statement, the signal 'x' is expected to be specified in terms of normalized frequency while the latter uses the actual frequency of the signal in Hz and the sampling frequency. To understand the difference better, consider the following code snippet:
n = 0:999;
x1 = cos(pi/4*n)+0.5*sin(pi/2*n);
fs = 1000;
t = 0:0.001:1-0.001;
x2 = cos(2*pi*125*t)+0.5*sin(2*pi*250*t);
freq = [125 250];
In the above case, both the signals x1 and x2 are basically the same signal but expressed using the two different representations (x1 uses normalized frequency and x2 uses the cyclical frequency).
The spectrogram for the two signals can be visualized using:
You can notice that the two spectrograms are similar except for a difference in the magnitudes of the power because they are represented in different units. In the first case, the units is dB/rad/sample while the second representation uses dB/Hz.
Computing the power spectral density of the two signals will give you a better insight about the difference. Consider the following lines of code:
[pxx1,w] = periodogram(x1,,[pi/4 pi/2]);
pxx2 = periodogram(x2,,freq,fs)
The magnitudes of pxx1 and pxx2 are different only due to the difference in the units. The conversion from one to another follows the relation:
PSD (in normalized frequency)= (PSD (in cyclical frequency) * Sampling frequency) /(2*pi).
More Answers (4)
Zulfidin Khodzhaev on 18 Dec 2018
Is it possible to get rid of "colorbar", which is automatically there with "spectrogram" command ?