Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python scipy.signal.remez high pass filter design yields strange transfer function

I'm trying to design equiripple high-pass filters using python's scipy.signal.remez function. However, the resulting transfer functions look very strange to me with ~ 15 db peaking in the pass band and only 6 dB stop band attenuation. The corresponding low-pass design looks ok (~ 0.1 dB pass band ripple and 40 dB stop band attenuation):

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Minimum working example for remez (equiripple) filter designs:
from __future__ import division, print_function
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt
F_PB = 0.1  # corner frequency of pass band
F_SB = 0.15 # corner frequency of stop band
W_PB = 1    # weight factor for pass band 
W_SB = 1    # weight factor for stop band
L = 40 # filter order
#b = sig.remez(L, [0, F_PB, F_SB, 0.5], [1, 0], [W_PB, W_SB], Hz = 1) # low pass
b = sig.remez(L, [0, F_PB, F_SB, 0.5], [0, 1], [W_PB, W_SB], Hz = 1) # high pass
# Calculate H(w), w = 0 ... pi, 1024 Pts.
[w, H] = sig.freqz(b, worN = 1024)
# Translate w to normalized frequencies F = 0 ... 0.5:                   
F = w / (2 * np.pi)   
plt.figure(1)
plt.plot(F, 20 * np.log10(abs(H)))
plt.title(r'Magnitude transfer function in dB')
plt.show()

Can anybody explain to me what's going on?

Cheers, Christian

like image 701
Chipmuenk Avatar asked Feb 04 '26 05:02

Chipmuenk


1 Answers

For a highpass filter with the default remez argument type='bandpass', use an odd number of taps. With an even number of taps, remez creates a Type II filter, which has a zero at the Nyquist frequency. The algorithm has a hard time creating a highpass filter with such a constraint.

Here's a plot of the gain when L = 41:

Remez result, L=41

OR use an even number of taps, and type='hilbert'. The following shows the result obtained with L=40 and type='hilbert':

Remez result, L=40, type='hilbert'

Note, however, that the FIR filter is Type IV in this case--the filter coefficients have odd symmetry.

like image 94
Warren Weckesser Avatar answered Feb 06 '26 18:02

Warren Weckesser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!