将两个变量相互绘制但得到两条线而不是一条线

Plotting two variables against each other but getting two lines instead of just one

在我的物理研究实习中,我正在分析酒杯的共振频率,这涉及导入音频文件并对其进行傅立叶变换(使用 scipy.fftpack)。所以一切都很顺利,但是当我绘制傅里叶变换时,我得到两条线:一条是您期望的图,但另一条是水平线 (see picture)。我查看了我正在绘制的变量,但似乎没有什么异常。

这是代码(您需要 this .wav file(耳机用户请注意耳朵!)):

import matplotlib.pyplot as plt
from scipy.io import wavfile as wav
from scipy.fftpack import fft,fftfreq
import numpy as np

#Read the .wav file here:  ˇˇˇˇˇˇˇˇˇˇˇ
rate, data = wav.read('C:\Users\ilike\OneDrive\Documenten\RP\RP2\Bewerkte .wav files\0 ml_bewerkt.wav')


#Take the Fourier transform of the .wav file. Take the log10 of it and normalize (so Fourier_ynorm is between 0 and 1) 
Fourier_y = np.log(abs(fft(data[:,0])))
Fourier_ynorm = Fourier_y/max(Fourier_y)
Fourier_x = fftfreq(len(data), 1/rate)
#The x-axis is in Hz, so a 1200 Hz beep would give a peak at 1200 and -1200

#These two lines plot the Fourier transform, but there is a weird horizontal line at y = 0.3
plt.plot(Fourier_x, Fourier_ynorm)
plt.xlim(1200,1400)

我想知道横线是怎么来的,怎么去掉。

编辑:我已经使用 fftshift 解决了这个问题。感谢所有提供帮助的人(对于新问题感到抱歉)!

单独Fourier_x的情节是这样的:

plt.plot(Fourier_x)

您似乎在 wav 文件中重复了两次相同的信号?

水平线是 non-monotonic Fourier_x 的人工制品,我认为

一个简单的解决方案是将绘图命令更改为

plt.plot(Fourier_x, Fourier_ynorm, '.')

这看起来像:

一个更高级的解决方案是understand/fix你在 wav 文件中有一个看起来像重复信号的事实