我正在尝试导入一个波形文件,并使用FFT分析(查找峰值)。然后用过滤器处理(例如去除噪音)。然后将其导出为新的wave文件。
实际过滤时似乎正在发生某些事情。
滤波信号出错,因为在绘制滤波器输出时,绘图给出了错误的时间轴数据,并且在某些情况下输出频谱偏移或根本没有给出。
我认为导入等工作正常,我从多个来源获取了它们。 主要来源:https://azitech.wordpress.com/2011/03/15/designing-a-butterworth-low-pass-filter-with-scipy/
#designing filter.
order = 10
lowcut = 950
highcut = 1050
fs = 44100
#^^^(fs) is this same sampling frequency of the import?
#find filter coefficients
def butter_bandpass(lowcut, highcut, fs, order):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = signal.butter(order, [low, high], btype='band')
return b,a
# Call filter to get coefficients
b, a = butter_bandpass(lowcut,highcut,fs,order)
print(b,a)
# filter frequency response
(w, h) = signal.freqz(b, a)
fig.add_subplot(131)
pyplot.plot((fs*0.5/numpy.pi)*w, numpy.abs(h)) #*w > fs*0.5/numpy.pi*
pyplot.title('Filter Respons Freq Domain')
print('Order filter','=',order)
pyplot.grid(True)
# Also not sure why source plots it as fs*0.5/numpy.pi < although this gives the right x-axis (frequency) as the input (highcut and lowcut).
# filtered output
#zi = signal.lfiltic(b, a, x[0:5], x[0:5])
#(y, zi) = signal.lfilter(b, a, x, zi=zi)
# ^^ not used.
y = signal.lfilter(b, a, data[:,0])
pyplot.plot(t, y)
pyplot.title('Filter Output Time Domain')
pyplot.grid(True)
最终产品需要是一个脚本,该脚本能够导入wav文件(这是采访和噪声(定义的峰值噪声)的组合,对其进行分析以达到峰值,然后将其导出为新的可播放波形文件