# Implementation of Filters in Python

I've implemented 2 filters in Python I would like to know if they look OK or not.. I've implemented an lowpass FIR Hann Filter and an lowpass IIR Chebyshev type 1 filter. My plots look like the following: Time amplitude and frequency spectrum: Hann Window:

Cheby 1: Is there something that I did wrong, that I should improve??

• Please show the frequency and phase response for the two filters using scipy.signal.freqz, that is what you should be comparing between the two and not spectrums of your actual data. Apr 19, 2020 at 16:33
• @DanBoschen edited the question, please see the last 2 plots Apr 19, 2020 at 16:37
• Plot with the y axis as dB using 20*np.log10(abs(h)), and better if you could paste just the plots and not your whole screen. Use Ctrl-Alt-PrintScreen once the window is selected to just copy that to your buffer Apr 19, 2020 at 16:44
• Sorry, I'll post just the plots Apr 19, 2020 at 17:00
• @DanBoschen posted what you've asked for Apr 19, 2020 at 17:10

After roughly observing the output spectrum, I found something strange.

First, I noticed that you're coping with audio(voice) signals. Because telephones are made to work in the ranges 300 Hz to 3400 Hz [1], it seems that your IIR filter has filtered out the frequency components higher than about 1kHz. Is that what you intended to do?

Second, I noticed that your FIR filter is a kind of LPF but I cannot do any further inference, because frequency/phase responses of impulse signal have not given. (you can create an impulse signal and then plot the spectrum as you have done.)

When it comes to the design of a filter, the spec of the filter should be discussed.

First, you need to assign the cut-off frequency (or which part of the signal do you want to filtered?). From the output spectrum of your signals, I suspect that you use two different cut-off frequencies when comparing IIR/FIR filter. If you just wanna filtered out high frequency noise, you need firstly decide the range. Maybe you can refer to [2].

Here are some frequently discussed basic spec from my experience.

1. Is application real-time or not? This can determine whether you can use the so-called filtfilt technique. (Zero delay at expense of causality. (you need to recorded all signal and))

2. Is General linear phase (GLP) required? If so, IIR in filtfilt or GLP FIR Filter are your choices.

3. Usually, IIR can obtain better stop band attenuation with lower orders. However, the delay might vary from different frequencies to other frequencies. For extremely bad example, the input is 'do re mi' but the output becomes 're mi do'.