求输入波形的fft。金融机构

2024-04-19 08:00:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做一个项目的树莓皮3,目标是应用带通滤波器的信号,但我目前有困难得到给定信号的快速傅立叶变换。我正在使用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)

Tags: tofrompyimportnumpytrueinputdata