Spectrogram windowing- why do the 2 methods generate different graphs?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (2)
Wayne King
el 28 de Nov. de 2013
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
Wayne King
el 28 de Nov. de 2013
Editada: Wayne King
el 28 de Nov. de 2013
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 comentarios
Win
el 28 de Nov. de 2013
Wayne King
el 28 de Nov. de 2013
Editada: Wayne King
el 28 de Nov. de 2013
I did not worry about optimizing the spectrogram. Your post was that the two function calls produce different results. They do not.
Sorry I made a mistake in the cutoff times, I used 0.2 and 0.4 instead of 2 and 4. I corrected it above and I plotted the results. The figures are identical.
Win
el 28 de Nov. de 2013
Win
el 28 de Nov. de 2013
Categorías
Más información sobre Digital Filter Design en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

