# Attenuate the low frequencies in a speech wave

I am designing an FIR filter to attenuate the frequencies below 300Hz. I designed the filter using the scipy functions and the code is as below.

from numpy import cos, sin, pi, absolute, arange
from scipy.signal import kaiserord, lfilter, firwin, freqz
from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid,
axes, show

nyq_rate = 48000 / 2
width = 100 / nyq_rate
ripple_db = 60.0
cutoff_hz = 300.0

N, beta = kaiserord(ripple_db, width)
taps = firwin(N, cutoff_hz/nyq_rate, window=('kaiser', beta), pass_zero='highpass')
w, h = freqz(taps, worN=512)

plot((w/pi)*nyq_rate, absolute(h), linewidth=2)
xlabel('Frequency (Hz)')
ylabel('Gain')
title('Frequency Response')
ylim(-0.05, 1.05)
grid(True)

show()


When I a execute it, the following error pops up.

ValueError: A filter with an even number of coefficients must have zero response at the Nyquist frequency.


I am not sure what is going wrong. Any help is appreciated.

• Okay. I think the error is using even number of filter coefficients. Adding 1 to N gets rid of the error. – Danny Jul 30 '19 at 11:52
• Possible duplicate of Low Pass FIR Filter – Jonas Schwarz Jul 30 '19 at 15:18

• How can I pass the attenuation factor for stop band as an input while deisgning filter in Python? In the scipy provided functions like kaiserord, there is an argument called ripple. But after assigining that argument to 12 dB I don't see the relative change in the frequency response. – Danny Jul 31 '19 at 12:16