python低通滤波器设计(FIR, IIR)

这里就只举简单的例子,关于具体的函数参数可以去python官网查看。

from scipy import signal
from soundfile import read, write


def low_pass_FIR(data):
    b = signal.firwin(15, 0.125)    # need more orders than IIR
    low_data = signal.lfilter(b, 1, data)
    return low_data


def low_pass_IIR(data):
    b, a = signal.butter(2, 0.125, btype='low', output='ba')
    low_data = signal.lfilter(b, a, data)
    return low_data


a = read('sample.wav')
# a1 = low_pass_IIR(a[0])
a1 = low_pass_FIR(a[0])
write('low_fir.wav', a1, a[1])

你可能感兴趣的:(Signal,Processing,Programming)