我正在尝试在Python中实现周期图。但结果与MATLAB不同。如何使结果匹配?
MATLAB代码:
Fs=8000;
y1=zeros(1,256);
for f =0:100:1900
for n=0:255
y1(n+1)=y1(n+1)+sin(2*pi*f*n/Fs);
end
end
[Sxxk,w] = computeperiodogram(y1,hamming(256),256);
display(Sxxk);
结果:
Sxxk =
0.0153
0.0257
1.0230
14.6425
4.9626
0.1737
...
Python代码:
Fs=8000
sample=256
frequencys=100 * np.arange(20)
y1=np.zeros(sample)
for f in range(frequencys.size):
for n in range(sample):
y1[n]=y1[n]+sin(2*pi*frequencys[f]*n/Fs)
f, tmp_periodogram = signal.periodogram(tmp_sig,
window=np.hamming(256), nfft=256 , detrend=False)
print(tmp_periodogram)
结果:
[ 9.59750208e-02 1.61666495e-01 6.42745227e+00 9.20012900e+01
3.11810128e+01 1.09163906e+00 7.78876698e+01 4.90721979e+01 ...
我看过帖子Periodogram in Octave/Matlab vs Scipy
但它没有给出如何获得与MATLAB相同结果的答案。有人可以分享他们的想法吗?