Python 用matplotlib绘制纯窦的频谱图
我想得到一个纯正弦函数的光谱图。同时,我想展示整个信号的fft图。我期望峰值在相同的频率上,因为我们处理的是相同的信号,在时间上是静止的 代码Python 用matplotlib绘制纯窦的频谱图,python,numpy,matplotlib,fft,Python,Numpy,Matplotlib,Fft,我想得到一个纯正弦函数的光谱图。同时,我想展示整个信号的fft图。我期望峰值在相同的频率上,因为我们处理的是相同的信号,在时间上是静止的 代码 samplingFrequency = 32. frequency = 4 #frequency of the sinus wave t = arange(0,20,1/samplingFrequency) #time intervals with period 1/sampling freque
samplingFrequency = 32.
frequency = 4 #frequency of the sinus wave
t = arange(0,20,1/samplingFrequency) #time intervals with period 1/sampling frequency
y = cos(2*pi*frequency*t)
Y = fft.fft(y) #standard fft on the whole signal
frequencyAxis = fft.fftfreq(len(Y),1/samplingFrequency ) #adjusting the x axis
#PLOTTING
fig, (ax1,ax2) = plt.subplots(nrows=2, ncols=1)
ax1.specgram(y, Fs = samplingFrequency)
ax2.stem(frequencyAxis,Y,linefmt='r--', markerfmt='ro')
绘图
整个信号的fft与预期一样,峰值为4。然而,spectrogram在12点绘制了一条线。关于错误在哪里的想法
更新
正在使用以下版本:
- matplotlib“1.1.1”
- numpy“1.6.2”
- python 2.7.3