查找输入的 wav 的 fft.文件

  • 本文关键字:fft 文件 wav 查找 python
  • 更新时间 :
  • 英文 :


我在树莓派 3 上做一个项目,目标是对信号应用带通滤波器,但我目前无法获得给定信号的 FFT。我正在使用python3,这是我到目前为止的代码:

import scipy
from scipy.io.wavfile import read
from scipy.signal import hann
from scipy.fftpack import rfft
import matplotlib.pyplot as plt
import numpy as np
from threading import *
input_data = read("/home/pi/Music/doorbell-1.wav")
np.array(input_data[1],dtype=float)
audio = input_data[1]
#apply a Hanning window
window = hann(1024)
audio = audio[0:1024] * window
# fft
mags = abs(rfft(audio))
# convert to dB
mags = 20 * scipy.log10(mags)
# normalise to 0 dB max
mags -= max(mags)
# plot
plt.plot(mags)
# label the axes
plt.ylabel("Magnitude (dB)")
plt.xlabel("Frequency Bin")
# set the title
plt.title("doorbell Spectrum")
plt.show()
#ERROR
/usr/lib/python3/dist-packages/numpy/lib/scimath.py:310: RuntimeWarning: 
divide by zero encountered in log10
return nx.log10(x)
MaynoothTest.py:18: RuntimeWarning: invalid value encountered in multiply
mags = 20 * scipy.log10(mags)
MaynoothTest.py:20: RuntimeWarning: invalid value encountered in subtract
mags -= max(mags)
[ True  True  True ...,  True  True  True]
/usr/lib/python3/dist-packages/numpy/core/numeric.py:531: ComplexWarning: 
Casting complex values to real discards the imaginary part
return array(a, dtype, copy=False, order=order)

audio包含两个通道(左和右(。您需要选择一个具有:audio = audio[0:1024, 1] .

最新更新