我有一个MATLAB程序,我想将其转移到Python。问题在于,我使用了内置的spectrogram
函数,虽然Matplotlib的specgram
函数看起来完全相同,但当我运行它们时会得到不同的结果。
这是我一直在运行的代码:
MATLAB:
data = 1:999; %Dummy data. Just for testing.
Fs = 8000; % All the songs we'll be working on will be sampled at an 8KHz rate
tWindow = 64e-3; % The window must be long enough to get 64ms of the signal
NWindow = Fs*tWindow; % Number of elements the window must have
window = hamming(NWindow); % Window used in the spectrogram
NFFT = 512;
NOverlap = NWindow/2; % We want a 50% overlap
[S, F, T] = spectrogram(data, window, NOverlap, NFFT, Fs);
Python:
import numpy as np
from matplotlib import mlab
data = range(1,1000) #Dummy data. Just for testing
Fs = 8000
tWindow = 64e-3
NWindow = Fs*tWindow
window = np.hamming(NWindow)
NFFT = 512
NOverlap = NWindow/2
[s, f, t] = mlab.specgram(data, NFFT = NFFT, Fs = Fs, window = window, noverlap = NOverlap)
以下是两次执行的结果:
http://i.imgur.com/QSPvYsC.png
(其中F和T变量在两个程序中完全相同)
很明显它们是不同的;实际上,Python执行甚至没有返回复数。问题可能出在哪里?有没有办法修复它或者我应该使用另一个频谱图函数呢?
非常感谢您的帮助。