필터 지우기
필터 지우기

Spectrogram windowing- why do the 2 methods generate different graphs?

조회 수: 4 (최근 30일)
Win
Win 2013년 11월 28일
댓글: Win 2013년 11월 28일
Method 1 spectrogram(x,128,16,128,FS)
Method 2 w = window(@hamming,128); [S,F,T,P] = spectrogram(x,w,16,128,FS);
Since I cannot change the window type in method 1, I am using method 2. I would like to know why there is a BIG difference in the figures generated.

채택된 답변

Wayne King
Wayne King 2013년 11월 28일
편집: Wayne King 2013년 11월 28일
That is a different question. The answer to that question is that calling spectrogram() with no output arguments is the same as providing the 'xaxis' option for FREQLOCATION (this is explained in the help).
That means that instead of having frequency on the y-axis as your second figure does and my figures too, you have frequency on the x-axis and time on the y-axis.
  댓글 수: 4
Wayne King
Wayne King 2013년 11월 28일
yes, you can manipulate the color axis by setting limits and or manipulating the color map. Also, you should overlap your windows more.
For example:
[S,F,T,P] = spectrogram(x,128,64,128,FS);
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;
view(0,90); caxis([-90 5])
Win
Win 2013년 11월 28일
Ok, that helps, thanks! :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Wayne King
Wayne King 2013년 11월 28일
Are you sure you are using MathWorks' version of spectrogram() and/or hamming()? Because I see no difference at all (and there should not be)
x = randn(1000,1);
FS = 1;
w = window(@hamming,128); [S,F,T,P] = spectrogram(x,w,16,128,FS);
[S1,F1,T1,P1] = spectrogram(x,128,16,128,FS);
isequal(S,S1) % returns a 1
isequal(P,P1) % also returns a 1
If you enter
>>which spectrogram
and
>>which hamming
Do you get paths that end in:
matlab\toolbox\signal\signal
  댓글 수: 2
Win
Win 2013년 11월 28일
I am using the spectrogram function but in the documentation it is said that hamming is the default window. Hence I tried to reproduce it using the second function. Here are my codes:
clear all; FS = 100; w1=2; w2=5; w3=40; i=1; for t=0:1/FS:10
if t<=2
x(i)=5*sin(2*pi*w1*t);
end
if (t>2)&& (t<=4)
x(i)=2*sin(2*pi*w2*t);
end
if (t>4)&& (t<=10)
x(i)=sin(2*pi*w3*t);
end
i=i+1;
end
%Method 1
%spectrogram(x,128,16,128,FS)
%Method 2
w = window(@hamming,128);
[S,F,T,P] = spectrogram(x,w,16,128,FS);
figure
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;
view(0,90);
Win
Win 2013년 11월 28일
On typing which spectrogram I get: C:\Program Files\MATLAB\R2012a\toolbox\signal\signal\spectrogram.m and on typing which hamming I get C:\Program Files\MATLAB\R2012a\toolbox\signal\signal\hamming.m

댓글을 달려면 로그인하십시오.


Wayne King
Wayne King 2013년 11월 28일
편집: Wayne King 2013년 11월 28일
Here I use your signal and they are identical:
FS = 100;
w1=2; w2=5; w3=40;
t=0:1/FS:10;
dt = 1/FS;
x = zeros(size(t));
idx1 = 2/dt+1;
idx2 = idx1+1:(4/dt+1);
idx3 = (4/dt+2):length(t);
x(1:idx1) = 5*sin(2*pi*w1*t(1:idx1));
x(idx2) = 2*sin(2*pi*w2*t(idx2));
x(idx3) = sin(2*pi*w3*t(idx3));
w = window(@hamming,128); [S,F,T,P] = spectrogram(x,w,16,128,FS);
[S1,F1,T1,P1] = spectrogram(x,128,16,128,FS);
isequal(S,S1) % returns a 1
isequal(P,P1) % also returns a 1
figure
surf(T,F,10*log10(P),'edgecolor','none'); axis tight;
view(0,90);
figure
surf(T,F,10*log10(P1),'edgecolor','none'); axis tight;
view(0,90);
And yes Hamming is the default window.
  댓글 수: 4
Win
Win 2013년 11월 28일
Ok, maybe I worded my question wrongly
On using the following lines: w = window(@hamming,128); [S,F,T,P] = spectrogram(x,w,16,128,FS); figure surf(T,F,10*log10(P),'edgecolor','none'); axis tight; view(0,90);
I get the figure below. I wanted to know why it's different to the figure above.
Win
Win 2013년 11월 28일
Ignoring the swap in axes of course as that can be easily fixed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by