# How to understand spectrogram function

100 ビュー (過去 30 日間)
Mark Golberg 2016 年 1 月 31 日

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.
and
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.
THANK YOU

サインインしてコメントする。

### 採用された回答

Vidya Viswanathan 2016 年 2 月 4 日
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:
[s1,w,t1]=spectrogram(x1,[],8,[pi/4 pi/2]);
figure,
spectrogram(x1,'yaxis')
[s2,f,t2]=spectrogram(x2,[],8,freq,fs);
figure,
spectrogram(x2,[],[],[],fs,'yaxis')
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).
##### 2 件のコメントなしを表示なしを非表示
Mark Golberg 2016 年 2 月 24 日
Thank you Vidya Viswanathan!!!
Mohannad suleiman 2021 年 2 月 27 日
dear vidya how can we show the (power / frequency ) in the figures

サインインしてコメントする。

### その他の回答 (5 件)

Jonathan Grimbert 2018 年 5 月 23 日
thanks Vidya Viswanathan for your answer. However I got a question on the X axis... How do you know it is in ms for the second spectrogram ?
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Zulfidin Khodzhaev 2018 年 12 月 18 日
Is it possible to get rid of "colorbar", which is automatically there with "spectrogram" command ?
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Pawan Sharma 2019 年 2 月 12 日
%% use this to get rid of the colorbar at the end of your plot syntax
colorbar off

サインインしてコメントする。

Mohannad suleiman 2021 年 2 月 27 日
dear vidya how can we show the (power / frequency ) in the figures
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Aditya Ramesh 2021 年 12 月 1 日
colorbar off
This disables the colorbar
colorbar on
This shows the colorbar without the bar label (power/frequency)
Colorbar with the legend label is shown by default even if no colorbar properties are defined. SO basically write nothign after spectrogram(.......) to get what you want.

サインインしてコメントする。

Christoph 2021 年 8 月 25 日
You can also have a look here --> https://github.com/Christoph-Lauer/Sonogram
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Lazaros Moysis 2023 年 3 月 14 日
Based on your comments and feedback, I want to understand, how could I compute the Spectrogram according to the Bark scale, which is
BandBarks = [20, 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, 3700, 4400, 5300, 6400, 7700];

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by