我正在做一个关于语音处理的项目。我想知道如何在Python中创建白噪声信号,并使用带通滤波器过滤噪声信号?
import pyaudio
import numpy as np
import scipy.signal as signal
CHUNK = 64 #the block size
Q = 50
pa = pyaudio.PyAudio()
stream = pa.open(format=pyaudio.paFloat32,
channels=1,
rate=44100,
output=True)
while True:
noise = np.random.uniform(-1,1,CHUNK)
b,a = signal.iirfilter(1,[2*500*(1-1/(2*Q))/44100,2*500*(1+1/(2*Q))/44100])
output = signal.lfilter(b,a,noise)
output.astype(np.float32)
output = output.tobytes()
stream.write(output)
代码是对的吗? signal.iirfilter
和signal.butter
之间有什么区别?
非常感谢你。