2010-07-20 93 views
2

在Matlabs近期版本,specgram功能正在被spectrogram替换,并且文档状态:Matlab的specgram过时VS谱图更换

注。要获取除去specgram功能相同的结果,指定长度256

不幸的“翰”窗口,这似乎并没有为我工作,如果我用spectrogram(signal,hann(256)),其结果是不同的specgram(signal),虽然都很相似。有没有办法获得完全相同的输出?

回答

3

我相信它们在每个函数中都有不同的计算。这是我能获得最好的:

sig = rand(1280,1); 
Fs = 2; 
nfft = 256; 
numoverlap = 128; 
window = hanning(nfft); 

%# specgram 
subplot(121), specgram(sig,nfft,Fs,window,numoverlap) 

%# spectrogram: make it look like specgram 
[S,F,T,P] = spectrogram(sig,window,numoverlap,nfft,Fs); 
subplot(122), imagesc(T, F, 20*log10(P)) 
axis xy, colormap(jet), ylabel('Frequency') 

spectrogram

+0

谢谢,我会在我的项目中尝试类似的东西,因为我不认为我需要完全相同的输出。 – dMaggot 2010-07-20 11:54:43

1

我目前还没有Matlab的尝试,但hann(256,'periodic')可能是你在找什么。

+0

这个命令非常接近specgram – dMaggot 2010-07-21 02:19:25

+0

我会很惊讶,因为如果你看一下specgram'edit specgram.m'的源代码,你会在133行左右发现它使用旧HANNING函数而不是HANN函数(尽管两者都是相同的,并且定义为'0.5 *(1-cos(2 * pi * n/nfft))'),其中'对称'作为默认选项 – Amro 2010-07-21 05:23:12

4

好吧,我只是偶然发现了解决方案:

specgram(singal) = spectrogram(signal, hanning(256))

因为hannhanning不是在Matlab同样的事情。

感谢大家的支持。