Sign in

Not a member? | Forgot your Password?

Search code

Search tips

Find us on Facebook!





Free PDF Downloads

A Quadrature Signals Tutorial: Complex, But Not Complicated

Understanding the 'Phasing Method' of Single Sideband Demodulation

Complex Digital Signal Processing in Telecommunications

Introduction to Sound Processing

C++ Tutorial

Introduction of C Programming for DSP Applications

Fixed-Point Arithmetic: An Introduction

Cascaded Integrator-Comb (CIC) Filter Introduction

IIR Filter Design Software

See Also

Embedded SystemsFPGA

DSP Code Sharing > Halfband Filter Design with Python/Scipy


Halfband Filter Design with Python/Scipy

Language: Python

Processor: Not Relevant

Submitted by Christopher Felton on Feb 24 2012

Licensed under a Creative Commons Attribution 3.0 Unported License

Halfband Filter Design with Python/Scipy


 

The following code snippet is an example how to design a half band filter.  Half band filters are interesting because every even coefficient, except 0, is 0.  Those multiplications do not need to be performed, additional calculation reduction can be gained by implementing a folded FIR (coeffecients are symmetric).  Only 1/4 the multiplies are required for a straight-forward implementation.  Also, polyphase implementations [1] reduce the required number of multiplications even further.

This code snippet is an example how to design a half band filter using the remez function in the Python scipy.signal package.

A half band filter can be designed using the Parks-McCellen equilripple design methods by having equal offsets of the pass-band and stop-band (from filter specification) and equal weights of the pass-band and stop-band [2].

Filter Specification:

Halfband filter specification

The code snippet below is an iPython session.  The numpy/scipy packages are required.  The "remez" function is part of the scipy.signal package.  The following plot is generated from the code snippet output and shows the filter response, in dB, for the filter length in the example.
Halfband filter response

Passband ripple

A commentor, @kaz, pointed out that the firwin design produces lower attenuation in the stopband and less ripple in the passband.  But the firwin design has a slower transition band.  In multi-rate systems which use the halfband filter and decimate by 2 more signal beyond Fs/4 will be aliased.  This is a consideration for the designer.  The windowed frequency sampling design (scipy.signal firwin, Matlab fir1) produces the same strucutre, every other coefficient 0 so it can be used in an optimized implementation.

Impulse response

The coefficients from this design are :

          remez       firwin
------------------------------------
tap 0 0.000000 0.000000
tap 1 -0.010233 -0.001888
tap 2 0.000000 0.000000
tap 3 0.010668 0.003862
tap 4 0.000000 0.000000
tap 5 -0.016324 -0.008242
tap 6 0.000000 0.000000
tap 7 0.024377 0.015947
tap 8 0.000000 0.000000
tap 9 -0.036482 -0.028677
tap 10 0.000000 0.000000
tap 11 0.056990 0.050719
tap 12 0.000000 0.000000
tap 13 -0.101993 -0.098016
tap 14 0.000000 0.000000
tap 15 0.316926 0.315942
tap 16 0.500009 0.500706
tap 17 0.316926 0.315942
tap 18 0.000000 0.000000
tap 19 -0.101993 -0.098016
tap 20 0.000000 0.000000
tap 21 0.056990 0.050719
tap 22 0.000000 0.000000
tap 23 -0.036482 -0.028677
tap 24 0.000000 0.000000
tap 25 0.024377 0.015947
tap 26 0.000000 0.000000
tap 27 -0.016324 -0.008242
tap 28 0.000000 0.000000
tap 29 0.010668 0.003862
tap 30 0.000000 0.000000
tap 31 -0.010233 -0.001888
tap 32 0.000000 0.000000  

Every other coeffecient is zero as expected.

[1] Lyons, Rick, "Understanding Digital Signal Processing", 3rd Ed, Pearson 2011
[2] Harris, Fred, "Multirate Signal Processing",  Pearson 2004
[3] McClellan, Parks, "A Personal History of the Parks-McClellan Algorithm", IEEE Signal Processing Magazine 2005.

 

 
 
 
Rate this code snippet:
5
Rating: 5 | Votes: 5
 
   
 
posted by Christopher Felton
Christopher Felton's current favorite projects are implementing DSP digital circuits with MyHDL for FPGAs. More information @ LinkedIn.



Comments


 

kaz wrote:

2/25/2012
 
Hi Christopher,

Your stopband is about -40dB, passband ripple is about 0.2dB.
Interestingly when I compared it to Matlab fir1:
h = fir1(30,.5);
I got -50dB stopband, 0.03dB passband ripple

Kadhiem
 

Christopher Felton wrote:

2/25/2012
 
@kaz  Thanks for the comment and the additional input of the windowed frequency sampling design method results.  I have updated the code snippet.  Note, the fir1 design produces a slower transition so this design method might not be as desirable in multi-rate systems because more signal will be aliased beyond the Fs/4 point.  This is a design trade-off that needs to be weighed, additional stopband attenuation vs slower transition.
 

linuxlizard wrote:

8/29/2012
 
Small fix: I added arange to the numpy import line.

from numpy import log10, abs, pi, arange
 

cfelton wrote:

8/29/2012
 
Thanks, I will get the code updated ASAP.

Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )