Objectives Describe the general concepts and approaches in IIR filter design. Demonstrate the design of digital oscillators by pole location. Demonstrate the design of sharp notch filters by pole-zero location. Describe the characteristics of the four types of classical prototype analog filters Demonstrate the design of analog filter prototypes with MATLAB®. Derive and describe the bilinear transformation. Demonstrate the bilinear transformation method of IIR filter design. Demonstrate the use of MATLAB functions for IIR design of filters with the response of classical analog filters. Demonstrate the effect of coefficient quantization on the performance of IIR filters.
Concepts in IIR Filter Design The frequency response of a DSP filter is the value of the z-domain transfer function on the unit circle The location of the poles and zeros determines the shape of the transfer function in the complex plane The poles must be inside the unit circle for stability
Typical IIR Filter Designs Digital Oscillators Notch Filters Digital Equivalents of Classical Analog Prototypes: –Butterworth –Chebyshev I –Chebyshev II –Elliptic or Cauer
Digital Oscillators Oscillator with frequency Ω 0 H(z) Impulse Digital Sinusoid X(z) Y(z)
Digital Oscillator Transfer Function Ω 0 is the oscillator digital frequency in radians A is the amplitude of the resulting sinusoid Often called a “two-pole resonator” because the transfer function has 2 poles at +/- Ω 0 exactly on the unit circle (“meta-stable”) For Hertzian frequencies use Ω = 2πf/f s
Oscillator Design Example Design an oscillator with a frequency of 200 Hz in a system operating with a sampling frequency of 8 kHz. The MATLAB solution is: >> f=200; >> fs=8000; >> omega=2*pi*f/fs; >> b=[0,sin(omega)]; >> a=[1,-2*cos(omega),1]; >> fvtool(b,a) % Use fvtool to display various results
Oscillator Design Example Results At a sampling frequency of 8 kHz each sample is 0.125 ms. 40 samples = 5 ms = the period of a 200 Hz sine function.
Oscillator Design Example Results Pole locations = ±Ω 0 = ±2π (200/8000) = ±0.1571 radians
Notch Filters Notch filters are designed by “pole/zero location” The zeros are located at the Ω notch frequencies Poles are placed close to the zeros locations, just inside the unit circle, to control the notch width. A gain factor is included to hold the filter gain to unity at all other frequencies Notch filters for multiple frequencies can be designed by cascading filters or, equivalently, by convolving the “a” and “b” coefficient vectors of individual filters
Notch Filter Transfer Function The following is the transfer function for a notch filter for a notch frequency Ω 0 and -3 dB width ΔΩ (or quality factor Q). The parameter r is the pole radius. The gain factor is g 0. Note the trade-off between pole radius and notch width.
Notch Filter Design Example Design a notch filter in MATLAB with a notch frequency of Ω 0 = π/4 and a Q factor of 20 >> omega=pi/4; >> Q=20; >> delta_omega=omega/Q; >> r=1-delta_omega/2; >> g=abs(1-2*r*cos(omega)+r^2)/(2*abs(1-cos(omega))); % The g0 factor >> bn=g*[1,-2*cos(omega),1]; % The b coefficients of the notch filter >> an=[1,-2*r*cos(omega),r^2]; %The a coefficients of the notch filter >> fvtool(bn,an)
Transfer Functions Analog Filter: Digital Filter:
MATLAB Prototype Filter Design Commands [B,A] = BUTTER(N,Wn) [B,A] = CHEBY1(N,R,Wn) [B,A] = CHEBY2(N,R,Wn) [B,A] = ELLIP(N,Rp,Rs,Wn) –N = filter order –R = pass band ripple (cheby1) or stop-band ripple (cheby2) in dB. (Rp and Rs respectively for the elliptic filter) –Wn = cut-off frequency (radians/sec for analog filters or normalized digital frequencies for digital filters) –[B,A] = filter coefficients, s-domain (analog filter) or z- domain (digital filter)
Analog Design Example Design an order 4 Elliptic analog filter with a cutoff frequency of 10 Hz, a maximum pass-band ripple of 1 dB, and a minimum stop-band attenuation of -20 dB. >> cutoff=2*pi*10; % Set the filter parameters >> order=4; >> Rp=1; >> Rs=20; >> [b,a]=ellip(order,Rp,Rs,cutoff,'s'); % Note the “s” option for an analog filter >> W=linspace(0,2*pi*20); % Create a 100 point linear frequency vector 0 to 20 Hz >> [H,f]=freqs(b,a,W); % The freqs command returns the complex value of the transfer function for the frequency vector W (copied into the vector f) >> plot(f/(2*pi),abs(H)) % Plot the magnitude of H versus the frequency in Hertz >> title('Order 4 Elliptic Filter with 10 Hz Cutoff Frequency') >> xlabel('Frequency, Hz') >> ylabel('Magnitude Response')
Digital Design of Analog Prototypes The Bilinear Transformation The bilinear transformation maps the complex variable “s” in the analog transfer function to the complex variable “z” in the digital transfer function
Design Steps for a DSP Implementation of an Analog Design Determine the desired cut-off frequency for the digital filter, Ω 0 Compute the equivalent cut-off frequency for the analog filter, ω 0, using the pre- warping equation. Design the analog filter (i.e., find its a and b coefficient vectors) Using the bi-linear transformation (s →z), compute the coefficients of the digital filter
MATLAB IIR Design Tools General Design Approach The MATLAB method for IIR filter design is a two command process; first, to determine the order and critical frequencies, second to compute the filter coefficients. For the a Butterworth filter: [N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) [B,A] = BUTTER(N,Wn,'type') where the option “type” can be either “high” or “stop” if specified. The command parameters are: –Wp = Ω pass-band edges in units of π –Ws = Ω stop-band edges in units of π –Rp = pass-band ripple in dB –Rs = stop-band ripple in dB
Design Example Filter Specifications: –Butterworth response –Pass-band edges = 400 Hz and 600 Hz –Stop-band edges = 300 Hz and 700 Hz –Pass-band ripple = 1 dB –Stop-band attenuation = -20 dB –Sampling Frequency = 2000 Hz
MATLAB Code for Design Example >> fs=2000; >> Wp=[2*400/fs,2*600/fs]; % Normalized digital frequencies of pass-band edges >> Ws=[2*300/fs,2*700/fs]; % Normalized digital frequencies of stop-band edges >> [N,Wn]=buttord(Wp,Ws,1,20); % The “order” command >> [B,A]=butter(N,Wn); % The “filter” command >> fvtool(B,A)
Design Example Results Band Edges (-1dB and -20 dB)
Design Example Chebyshev II High-Pass Filter Filter specifications: –Chebyshev II response (stop-band ripple) –Pass-band edge = 1000 Hz –Stop-band edge = 900 Hz –Pass-band ripple = 1 dB –Stop-band attenuation = -40 dB –Sampling frequency = 8 kHz
MATLAB Code for Design Example >> fs=8000; >> Wp=[2*1000/fs]; % Pass-band edge normalized digital frequency >> Ws=[2*900/fs]; % Stop-band edge normalized digital frequency >> [N,Wn]=cheb2ord(Wp,Ws,1,40); % The “order” command >> [B,A]=cheby2(N,40,Wn,'high'); % cheby2 is the “filter” command. In this command % the syntax requires the stop-band attenuation % as the second parameter >> fvtool(B,A)
Comparison of an Elliptic Filter with a Parks-McClellan Design Filter Specification: –Low-pass response –Pass-band edge = 475 Hz –Stop-band edge = 525 Hz (i.e., a transition width of 50 Hz) –Pass-band ripple less than 0.01 in absolute terms ( = 20log10(1-.01) = 0.0873 dB) –Stop-band attenuation greater than -40 dB (= 0.01 ripple in absolute terms) –Sampling frequency = 2000 Hz
Finding the Order of a P-M Design [N,Fo,Ao,W] = FIRPMORD(F,A,DEV,Fs) B = FIRPM(N,Fo,Ao,W) –N = order –F = band edges, Ω in units of π, or in Hz if Fs is specified –A = amplitudes corresponding to the bands defined by the edges in F [length(F) must be 2*length(A)-2] –DEV = deviation (ripple) in each band defined by F in absolute units (not dB) –Fs = sampling frequency in Hz
P-M Design to Specifications >> F = [475,525]; >> A = [1,0]; >> DEV = [.01,.01]; >> Fs = 2000; >> [N,Fo,Ao,W] = firpmord(F,A,DEV,Fs); >> B = firpm(N,Fo,Ao,W); >> fvtool(B,1) >> N N = 78
Coefficient Quantization The poles of an IIR filter must remain within the unit circle in the complex plane for stability Quantization and round-off errors can move the poles and create an unusable design
Effect of Coefficient Quantization Chebyshev II High-pass Filter Double Precision vs. 16 bits >> B16=quantize(B,16); >> A16=quantize(A,16);
Summary IIR filters can be design by pole-zero location –Digital oscillators: poles on the unit circle –Notch filters: zeros on the unit circle with nearby poles to control notch width Classic analog filters can be designed using the bilinear transformation IIR filters have the advantage of smaller filter order for a given frequency response. IIR filters have the disadvantages of possible instability due to coefficient quantization effects and non-linear phase response.