Design IIR Butterworth Filters Using 12 Lines of Code

Similar documents
Design IIR Filters Using Cascaded Biquads

IIR digital filter design for low pass filter based on impulse invariance and bilinear transformation methods using butterworth analog filter

ELEG 305: Digital Signal Processing

Chapter 7: IIR Filter Design Techniques

Digital Signal Processing IIR Filter Design via Bilinear Transform

EE482: Digital Signal Processing Applications

Butterworth Filter Properties

Digital Signal Processing

PS403 - Digital Signal processing

Lecture 9 Infinite Impulse Response Filters

Digital Signal Processing

DIGITAL SIGNAL PROCESSING. Chapter 6 IIR Filter Design

Discrete-Time David Johns and Ken Martin University of Toronto

Digital Control & Digital Filters. Lectures 21 & 22

INFINITE-IMPULSE RESPONSE DIGITAL FILTERS Classical analog filters and their conversion to digital filters 4. THE BUTTERWORTH ANALOG FILTER

DIGITAL SIGNAL PROCESSING UNIT III INFINITE IMPULSE RESPONSE DIGITAL FILTERS. 3.6 Design of Digital Filter using Digital to Digital

Cast of Characters. Some Symbols, Functions, and Variables Used in the Book

2.161 Signal Processing: Continuous and Discrete Fall 2008

ECE 410 DIGITAL SIGNAL PROCESSING D. Munson University of Illinois Chapter 12

Recursive, Infinite Impulse Response (IIR) Digital Filters:

From Continuous-Time Domain to Microcontroller Code

An Iir-Filter Example: A Butterworth Filter

Analog and Digital Filter Design

Digital Signal Processing Lecture 8 - Filter Design - IIR

Design of IIR filters

Digital Signal Processing 2/ Advanced Digital Signal Processing, Audio/Video Signal Processing Lecture 10, Frequency Warping, Example

Discrete Time Systems

Filter Analysis and Design

Like bilateral Laplace transforms, ROC must be used to determine a unique inverse z-transform.

butter butter Purpose Syntax Description Digital Domain Analog Domain

Speaker: Arthur Williams Chief Scientist Telebyte Inc. Thursday November 20 th 2008 INTRODUCTION TO ACTIVE AND PASSIVE ANALOG

Lecture 3 - Design of Digital Filters

V. IIR Digital Filters

On the Frequency-Domain Properties of Savitzky-Golay Filters

Solutions to Problems in Chapter 4

Up-Sampling (5B) Young Won Lim 11/15/12

Signals and Systems. Lecture 11 Wednesday 22 nd November 2017 DR TANIA STATHAKI

SIGNALS AND SYSTEMS LABORATORY 4: Polynomials, Laplace Transforms and Analog Filters in MATLAB

w n = c k v n k (1.226) w n = c k v n k + d k w n k (1.227) Clearly non-recursive filters are a special case of recursive filters where M=0.

Lecture 10 Filtering: Applied Concepts

MITOCW watch?v=jtj3v Rx7E

E : Lecture 1 Introduction

Multimedia Signals and Systems - Audio and Video. Signal, Image, Video Processing Review-Introduction, MP3 and MPEG2

Stability and Frequency Response of Linear Systems

1 1.27z z 2. 1 z H 2

DSP-CIS. Chapter-4: FIR & IIR Filter Design. Marc Moonen

Lecture 8 - IIR Filters (II)

Optimum Ordering and Pole-Zero Pairing of the Cascade Form IIR. Digital Filter

2.161 Signal Processing: Continuous and Discrete

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING EC2314- DIGITAL SIGNAL PROCESSING UNIT I INTRODUCTION PART A

Grades will be determined by the correctness of your answers (explanations are not required).

Signals, Instruments, and Systems W5. Introduction to Signal Processing Sampling, Reconstruction, and Filters

Down-Sampling (4B) Young Won Lim 11/15/12

Lecture 7 Discrete Systems

EE 521: Instrumentation and Measurements

Lecture 7 - IIR Filters

Problem Set 9 Solutions

Linear systems, small signals, and integrators

UNIVERSITY OF OSLO. Please make sure that your copy of the problem set is complete before you attempt to answer anything.

UNIVERSITY OF OSLO. Faculty of mathematics and natural sciences. Forslag til fasit, versjon-01: Problem 1 Signals and systems.

Fourier Methods in Digital Signal Processing Final Exam ME 579, Spring 2015 NAME

Introduction to DSP Time Domain Representation of Signals and Systems

24 Butterworth Filters

Laplace Transform Analysis of Signals and Systems

All-Pole Recursive Digital Filters Design Based on Ultraspherical Polynomials

Signal Processing First Lab 11: PeZ - The z, n, and ˆω Domains

Chapter 7: Filter Design 7.1 Practical Filter Terminology

Notes on L (Optimal) Filters

Down-Sampling (4B) Young Won Lim 10/25/12

Transform Representation of Signals

EE482: Digital Signal Processing Applications

ECE503: Digital Signal Processing Lecture 5

FROM ANALOGUE TO DIGITAL

Grades will be determined by the correctness of your answers (explanations are not required).

The Laplace Transform

APPLIED SIGNAL PROCESSING

Electronic Circuits EE359A

Matched Second Order Digital Filters

Signals and Systems. Problem Set: The z-transform and DT Fourier Transform

Responses of Digital Filters Chapter Intended Learning Outcomes:

Lecture 8 - IIR Filters (II)

Digital Signal Processing

Multirate Digital Signal Processing

EE Experiment 11 The Laplace Transform and Control System Characteristics

( ) John A. Quinn Lecture. ESE 531: Digital Signal Processing. Lecture Outline. Frequency Response of LTI System. Example: Zero on Real Axis

DEPARTMENT OF EI DIGITAL SIGNAL PROCESSING ASSIGNMENT 1

Digital Signal Processing

Shifted-modified Chebyshev filters

Higher-Order Σ Modulators and the Σ Toolbox

Oversampling Converters

Examination with solution suggestions SSY130 Applied Signal Processing

Solution: K m = R 1 = 10. From the original circuit, Z L1 = jωl 1 = j10 Ω. For the scaled circuit, L 1 = jk m ωl 1 = j10 10 = j100 Ω, Z L

DSP First Lab 11: PeZ - The z, n, and ωdomains

A.1 THE SAMPLED TIME DOMAIN AND THE Z TRANSFORM. 0 δ(t)dt = 1, (A.1) δ(t)dt =

SEL4223 Digital Signal Processing. Inverse Z-Transform. Musa Mohd Mokji

Detailed Solutions to Exercises

DSP Configurations. responded with: thus the system function for this filter would be

David Weenink. First semester 2007

Active Filter Design by Carsten Kristiansen Napier University. November 2004

CMPT 889: Lecture 5 Filters

Transcription:

db Design IIR Butterworth Filters Using 12 Lines of Code While there are plenty of canned functions to design Butterworth IIR filters [1], it s instructive and not that complicated to design them from scratch. You can do it in 12 lines of Matlab code. In this article, we ll create a Matlab function butter_synth.m to design lowpass Butterworth filters of any order. Here is an example function call for a 5 th order filter: N= 5 % Filter order fc= 1; % Hz cutoff freq fs= 1; % Hz sample freq [b,a]= butter_synth(n,fc,fs) b =.13.64.128.128.64.13 a = 1. -2.9754 3.86-2.5453.8811 -.1254 Then, to find the frequency response: [h,f]= freqz(b,a,256,fs); H= 2*log1(abs(h)); The magnitude response of the 5 th order filter is shown in Figure 1, along with the response of the analog prototype. -1-2 -3-4 -5 analog -6-7 -8 5 1 15 2 25 3 35 4 45 5 Hz Figure 1. Magnitude response of N= 5 IIR Butterworth filter with f c = 1 Hz and f s = 1 Hz. The prototype analog filter s response is also shown. 1

Notation First, a word about notation. We need to distinguish frequency variables in the continuous-time (analog) world from those in the discrete-time world. In this article, the following notation for frequency will be used: continuous frequency F Hz continuous radian frequency Ω radians/s complex frequency s = σ + jω discrete frequency f Hz Background discrete normalized radian frequency ω = 2πf/f s radians, where f s = sample frequency Analog Butterworth filters have all-pole transfer functions. For example, a third-order Butterworth filter with Ω c = 1 rad/s has the transfer function: or where the subscript a denotes analog (s-plane) poles. The poles in the s-plane are: p a = -.5 + j.866 p a1 = -1 p a2 = -.5 -j.866 We will transform the poles in the s-plane to poles in the z-plane using the bilinear transform [2,3]. The bilinear transform converts H(s) to H(z) by replacing s with: where f s is sample frequency. If we solve for z, we get: Equation 3 maps a point on the s plane to a point on the z plane. For example, if f s = 2 Hz, the s-plane real pole at -1 maps to: 2

For the 3 rd order filter, with Ω c = 1 and f s = 2, the z-plane poles fall as shown in Figure 2. From equation 1, H(s) has 3 zeros at s=. How do they map to the z plane? We will show later that the bilinear transform maps - to on the jω axis to -f s /2 to f s /2 on the unit circle. So the 3 zeros of H(s) map to +/- f s /2 on the unit circle, which corresponds to z= -1. (Recall that on the unit circle, z= e jω, where ω = 2πf/f s. For f = +/-f s /2, we have ω = +/-π, so z = e jπ = -1). The three zeros are represented by the o in figure 2. We can now write the 3 rd -order Butterworth H(z) as: where, from equation 3, p= [.7143 +j.33.6.7143 -j.33]. Expanding the numerator and denominator, we have: Where b = [1 3 3 1] and a= [1-2.286 1.4762 -.3714]. K is chosen to make gain = 1 at ω= : K = 1/H(ω=) = 1/H(z=1) = sum(a)/sum(b)=.952 Looking again at Figure 1, you may have wondered why the attenuation of the IIR filter is greater than that of the analog filter as f approaches f s /2. The reason is that the analog filter s zeros are at, while the bilinear transform compresses the frequency scale so that the IIR filter s zeros are at f s /2. 3

Imag 1.8.6.4.2 f= fs/2 f= -.2 -.4 -.6 -.8-1 -1 -.5.5 1 Real Figure 2. Z-plane Poles and zeros of 3 rd order IIR Butterworth filter with Ω c = 1 and f s = 2. Filter Synthesis Here is a summary of the steps for finding the filter coefficients : 1. Find the poles of the analog prototype filter with Ω c = 1 rad/s. 2. Given the desired f c of the digital filter, find the corresponding analog frequency F c. 3. Scale the s-plane poles by 2πF c. 4. Transform the poles from the s-plane to the z-plane. 5. Add N zeros at z = -1. 6. Convert poles and zeros to polynomials with coefficients a n and b n. Now let s look at the steps in detail. Note we ll repeat a lot of the math we already presented above. A Matlab function butter_synth that performs the filter synthesis is provided in the Appendix. It gives the same results as the built-in Matlab function butter(n,wn) [1]. 1. Poles of the analog filter. For a Butterworth filter of order N with Ω c = 1 rad/s, the poles are given by [4,5]: where 4

2. Given the desired f c, find analog frequency F c. As we ll show in the next section, the bilinear transform does not map the analog frequency F to discrete frequency f linearly. To achieve a digital filter cut-off frequency of f c, the analog prototype cut-off frequency must be: This exercise is called frequency pre-warping. For example, if f s = 1 Hz and we want f c = 2 Hz, then F c = 23.13 Hz. 3. Scale the s-plane poles by 2πF c. The poles obtained in step 1 gave Ω c = 1 rad/s (i.e. 1/(2π) Hz). Multiplying the poles by 2πF c scales the analog filter cut-off frequency to F c and the digital filter cut-off frequency to f c. 4. Transform the poles from the s-plane to the z-plane using the bilinear transform. From equation 3, 5. Add N zeros at z = -1. Following the example of equation 4, the numerator of H(z) is (z + 1) N, meaning there are N poles at z = -1. We now can write H(z) as: In butter_synth, we represent the N zeros as a vector q= -ones(1,n). 6. Convert poles and zeros to polynomials with coefficients a n and b n. If we expand the numerator and denominator of equation 6, we get polynomials in z -n : The Matlab code to perform the expansion is: a= poly(p) a= real(a) b= poly(q) We want H(z) to have a gain of 1 at ω=. Letting z= e jω, we have z= 1. Then, referring to equation 7, we have gain at ω= of: 5

db So, for gain of 1 at ω=, we make. Figure 3 shows the frequency response vs. order N for filters synthesized by butter_synth. Figure 4 shows the impulse response vs. order N for three cases. -1-2 -3-4 N= 9 N= 7 N= 5 N= 3 N= 2-5 -6-7 -8 5 1 15 2 25 3 35 4 45 5 Figure 3. IIR Butterworth magnitude responses for f c = 1 Hz and f s = 1 Hz. [h,f]= freqz(b,a,256,fs); H= 2*log1(abs(h)); Hz 6

.1 N= 2.8 N= 3 N= 5.6.4.2 -.2.5 1 1.5 2 2.5 3 t (ms) Figure 4. IIR Butterworth impulse responses for f c = 1 khz and f s = 32 khz. x= [1 zeros(1,95)]; % impulse y= filter(b,a,x); % impulse response Frequency Mapping of the Bilinear Transform The bilinear transform does not map the continuous frequency F to discrete frequency f linearly. To show this, we evaluate equation 2 for s= jω and z= e jω : Now substitute Ω= 2πF and ω= 2πf/f s : Figure 5 plots equation 8 for fs= 1 Hz. The entire analog frequency range maps to f s /2 to f s /2. Also shown on the zoomed plot on the right is the transformation of discrete frequency f = 2 Hz to continuous frequency F = 23.13 Hz. Note that the frequency mapping is approximately linear for f < f s /1 or so. 7

db F (Hz) F (Hz) Figure 6 shows the effect of using equation 8 to pre-warp the cut-off frequency of an analog prototype filter to give f c = 2 Hz. With pre-warping, the analog prototype poles were scaled by 2π*23.13. Without pre-warping, they were scaled by 2π*2. 1 4 8 6 4 2 3 2 1-2 -4-6 -8-1 -2-3 -1-5 5 f (Hz) -4-2 -1 1 2 f (Hz) Figure 5. Frequency mapping of the bilinear transform for f s = 1 Hz. x axis is discrete frequency and y- axis is continuous frequency. The right plot is a zoomed version of the left plot, showing the value of F for f = 2 Hz. -1-2 -3 not pre-warped pre-warped -4-5 -6-7 -8 5 1 15 2 25 3 35 4 45 5 Hz Figure 6. Effect of pre-warping for f c = 2 Hz and f s = 1 Hz. 5 th order IIR Butterworth. 8

References 1. Mathworks website https://www.mathworks.com/help/signal/ref/butter.html 2. Oppenheim, Alan V. and Shafer, Ronald W., Discrete-Time Signal Processing, Prentice Hall, 1989, section 7.1.2 3. Lyons, Richard G., Understanding Digital Signal Processing, 2 nd Ed., Pearson, 24, section 6.5 4. Williams, Arthur B. and Taylor, Fred J., Electronic Filter Design Handbook, 3 rd Ed., McGraw-Hill, 1995, section 2.3 5. Analog Devices Mini Tutorial MT-224, 212 http://www.analog.com/media/en/trainingseminars/tutorials/mt-224.pdf Neil Robertson December 217 9

Appendix Matlab Function butter_synth (12 lines of code, excluding error check) This program is provided as-is without any guarantees or warranty. The author is not responsible for any damage or losses of any kind caused by the use or misuse of the program. % butter_synth.m 12/9/17 Neil Robertson % Find the coefficients of an IIR butterworth lowpass filter using bilinear transform % % N= filter order % fc= -3 db frequency in Hz % fs= sample frequency in Hz % b = numerator coefficients of digital filter % a = denominator coefficients of digital filter function [b,a]= butter_synth(n,fc,fs); if fc>=fs/2; error('fc must be less than fs/2') end % I. Find poles of analog filter k= 1:N; theta= (2*k -1)*pi/(2*N); pa= -sin(theta) + j*cos(theta); % poles of filter with cutoff = 1 rad/s % II. scale poles in frequency Fc= fs/pi * tan(pi*fc/fs); pa= pa*2*pi*fc; % continuous pre-warped frequency % scale poles by 2*pi*Fc % III. Find coeffs of digital filter % poles and zeros in the z plane p= (1 + pa/(2*fs))./(1 - pa/(2*fs)); % poles by bilinear transform q= -ones(1,n); % zeros % convert poles and zeros to polynomial coeffs a= poly(p); % convert poles to polynomial coeffs a a= real(a); b= poly(q); % convert zeros to polynomial coeffs b K= sum(a)/sum(b); % amplitude scale factor b= K*b; 1