我有matlab代码:
data = 1:999;
Fs = 8000;
tWindow = 64e-3;
NWindow = Fs*tWindow;
window = hamming(NWindow);
NFFT = 512;
NOverlap = NWindow/2;
[S, F, T,P] = spectrogram(data, window, NOverlap, NFFT, Fs);
在python中
import numpy as np
from matplotlib import mlab
data = range(1,1000)
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, mode = 'complex')
上面的代码基于我在互联网上找到的示例。问题是我不能从python和MatLab中得到相同的结果。哪里会有问题?你知道吗
我相信您比较了错误的结果参数,即
S
到s
。你知道吗MATLAB ^{} 文档说明(变量名根据您的示例更改)。你知道吗
更进一步
为了进行比较,^{} 文档中说
这意味着MATLAB
spectrogram
返回值P
和matplotlib.mlab.specgram
返回值s
包含功率谱密度值,是要比较的参数。注意,您必须在mlab.specgram
中使用mode=psd
作为kwarg。你知道吗所以MATLAB:
和
mlab.specgram
我们是平等的。你知道吗
相关问题 更多 >
编程相关推荐