I'm doing a project about speech processing. I wonder how to create a white noise signal in Python, and filter the noise signal with bandpass filter?
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)
Is the code right? And what is the difference between signal.iirfilter
and signal.butter
?
Thank you very much.