Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB与Python的不同谱图_Python_Matlab_Matplotlib_Signal Processing_Spectrogram - Fatal编程技术网

MATLAB与Python的不同谱图

MATLAB与Python的不同谱图,python,matlab,matplotlib,signal-processing,spectrogram,Python,Matlab,Matplotlib,Signal Processing,Spectrogram,我有一个MATLAB程序,我想把它移植到Python。问题是,在它中,我使用了内置的spectrogram函数,尽管matplotlibspecgram函数似乎相同,但当我同时运行这两个函数时,我得到的结果不同 这就是我一直在运行的代码 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 rat

我有一个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)
这是我在两次执行中得到的结果:

(两个程序中的F和T变量完全相同)

很明显,他们是不同的;事实上,Python执行甚至不返回复数。有什么问题吗?有没有办法修复它,或者我应该使用另一个光谱图函数


非常感谢您的帮助。

matplotlib
中,
specgram
默认返回功率谱密度(
mode='PSD
)。在
MATLAB
中,
spectrogram
默认返回短时傅里叶变换,除非
nargout==4
,在这种情况下,它还计算
PSD
。要使
matplotlib
行为与
MATLAB
行为相匹配,请设置
mode='complex'

novellap值是否相同?如果使用python2,请尝试以下操作:novellap=NWindow/2.0