Lowpass Hann filter in Python I'm trying to design a FIR lowpass filter using Hann windowing in Python but I don't know where to start from... I have fc1,fc2, ft, rp and rs as parameters. This is my Python code:

            import myDSP
        import matplotlib.pyplot as plt
        import scipy.signal as signal
        import numpy as np

        def plotInTime(x,fs):
t=np.arange(0,np.size(x,0)/fs,1/fs)
plt.figure()
plt.plot(t,x)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.grid(True)

def plotInFrequency(x,fs):
N=int(np.size(x,0)/2)
if np.size(x,0)==1:
X=np.fft.fft(x,axis=1)
else:
X=np.fft.fft(x,axis=0)
X=np.abs(X)
X=X[:N]
f=np.arange(0,fs/2,fs/2/N)
plt.figure()
plt.plot(f,X)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.grid(True)
        fs, x = myDSP.readWav('Ring05c.wav') #is 22050
        myDSP.plotInTime(x,fs)
        plt.title('Original Signal')
        myDSP.plotInFrequency(x,fs)
        plt.title('Spectrum for the Original Signal')

        fc1=1200
        fc2=3000
        fc= np.arange(fc1,fc2+1)
        ft=150
        rp=0.1
        rs=40
        t = np.linspace(-1, 1, 201)
        #x = (np.sin(2*np.pi*0.75*t*(1-t) + 2.1)+0.1*np.sin(2*np.pi*1.25*t + 1) +0.18*np.cos(2*np.pi*3.85*t))
        wp=(fc-ft/2)/(fs/2)
        wp = wp[0]
        ws=(fc+ft/2)/(fs/2)
        ws = ws[0]
        L, Wn = signal.cheb1ord(wp,ws, rp, rs);
        b, a = signal.cheby1(L, rp, Wn,'low')
        f,H=signal.freqz(b,a,worN=256,plot=None,fs=fs)    

        y=signal.lfilter(b,a,x,axis=0)
        myDSP.plotInTime(y,fs)
        plt.title('Filtered Cheby1 Signal')

        myDSP.plotInFrequency(y,fs)
        plt.title('Spectrum for the Filtered Cheby1 Signal')
        y=y.astype('int16')

        w_fir = signal.firwin(65, fc/(fs/2), window='hann')
    [w,h] = signal.freqz(w_fir)
    plt.plot(w, 20*np.log10(abs(h)))
    plt.plot(w, np.angle(h))
You should read the documentation when using new functions: scipy.signal.firwin


You either provide pass_zero option or two cutoff frequencies. So in your case you don't have to use this option.
The first argument corresponds to the length of the filter. So it has to be an odd integer.
You either provide the sampling frequency or express the cutoff frequencies as relative frequencies (in your case something like fc1/fs).


In summary, for a a filter of order n, you can get your coefficients as

signal.firwin(n + 1, [fc1, fc2], fs=fs, window='hann')