我试着用scipy.signal.spectogram
创建一个星光图。
不幸的是我没有让它工作。你知道吗
我的测试信号应该是频率为400赫兹,振幅为1的正弦信号。spectogram的结果似乎是0.5而不是1.0。我不知道会有什么问题。你知道吗
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
# 2s time range with 44kHz
t = np.arange(0, 2, 1/44000)
# test signal: sine with 400Hz amplitude 1
x = np.sin(t*2*np.pi*440)
# spectogram for spectrum of magnitudes
f, t, Sxx = signal.spectrogram(x,
44000,
"hanning",
nperseg=1000,
noverlap=0,
scaling="spectrum",
return_onesided=True,
mode="magnitude"
)
# plot last frequency plot
plt.plot(f, Sxx[:,-1])
print("highest magnitude is: %f" %np.max(Sxx))
严格的实时信号在频域是共轭对称的。e、 g.将出现在复数结果的正半部分和负半部分(或上半部分)。你知道吗
因此,您需要将FFT结果的两个“一半”相加,以得到总能量(Parseval定理)。或者只是双面,因为复共轭具有相同的大小。你知道吗
相关问题 更多 >
编程相关推荐