Sibbs Gambling
Sibbs Gambling

Reputation: 20345

Where goes wrong for this High Pass Filter in Python?

# Specifications for HPF
Wp = 0.01 # Cutoff frequency 
Ws = 0.004 # Stop frequency 
Rp = 0.1 # passband maximum loss (gpass)
As = 60 # stoppand min attenuation (gstop)
b,a = fd.iirdesign(Wp, Ws, Rp, As, ftype='butter')
y = sig.lfilter(b, a, x, axis=-1)

I adjusted the parameters but the result never turned up as expected.

For example, when I decreased Wp, I was expecting that more frequency components survived after the filtering. Thus, I expected to see a more "shaky" signal.

However, it turned out to be 0 everywhere.

It seems that my understanding on this HPF is wrong.

Is it correct to do this to implement a HPF?

How may I adjust the parameters?

Upvotes: 1

Views: 624

Answers (1)

Ilja Everilä
Ilja Everilä

Reputation: 52929

It would seem that your transition band is too tight for iirdesign tool. The resulting filter has a large gain boost at low frequencies, essentially creating a lowpass filter after all. Try creating your filter with for example

Wp = 0.1
Ws = 0.04

This should give you a highpass filter. Try plotting the resulting coefficients with octave or matlab freqz function for checking that it produced the desired filter response.

If you must have such a narrow transition, you can try other than butterworth filter types. For example elliptic manages to produce the desired cutoff, transition and stop, but introduces ringing on both pass and stop bands (and a non-linear phase response).

b, a = fd.iirdesign(0.1, 0.04, 0.1, 60, ftype='ellip')

Upvotes: 3

Related Questions