















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The principal IIR digital filter design technique this toolbox provides is based on the conversion of classical lowpass analog filters to their digital ...
Typology: Study notes
1 / 55
This page cannot be seen from the preview
Don't miss anything!
















































Filter design is the process of creating the filter coefficients to meet specific filtering requirements. Filter implementation involves choosing and applying a particular filter structure to those coefficients. Only after both design and implementation have been performed can data be filtered. The following chapter describes filter design and implementation in the Signal Processing Toolbox.
Filter Requirements and Specification (p. 2-2)
Overview of filter design
IIR Filter Design (p. 2-4) Infinite impulse reponse filters (Butterworth, Chebyshev, elliptic, Bessel, Yule-Walker, and parametric methods)
FIR Filter Design (p. 2-17) Finite impulse reponse filters (windowing, multiband, least squares, nonlinear phase, complex filters, raised cosine)
Special Topics in IIR Filter Design (p. 2-44)
Analog design, frequency transformation, filter discretization
Filter Implementation (p. 2-53) Filtering with your filter
Selected Bibliography (p. 2-55) Sources for additional information
The goal of filter design is to perform frequency dependent alteration of a data sequence. A possible requirement might be to remove noise above 30 Hz from a data sequence sampled at 100 Hz. A more rigorous specification might call for a specific amount of passband ripple, stopband attenuation, or transition width. A very precise specification could ask to achieve the performance goals with the minimum filter order, or it could call for an arbitrary magnitude shape, or it might require an FIR filter. Filter design methods differ primarily in how performance is specified. For “loosely specified” requirements, as in the first case above, a Butterworth IIR filter is often sufficient. To design a fifth-order 30 Hz lowpass Butterworth filter and apply it to the data in vector x: [b,a] = butter(5,30/50); Hd = dfilt.df2t(b,a); %Direct-form II transposed structure y = filter(Hd,x);
The second input argument to butter specifies the cutoff frequency, normalized to half the sampling frequency (the Nyquist frequency). All of the filter design functions operate with normalized frequencies, so they do not require the system sampling rate as an extra input argument. This toolbox uses the convention that unit frequency is the Nyquist frequency, defined as half the sampling frequency. The normalized frequency, therefore, is always in the interval 0 ≤ f ≤ 1. For a system with a 1000 Hz sampling frequency, 300 Hz is 300/500 = 0.6. To convert normalized frequency to angular frequency around the unit circle, multiply by π. To convert normalized frequency back to hertz, multiply by half the sample frequency.
More rigorous filter requirements traditionally include passband ripple (Rp, in decibels), stopband attenuation (Rs, in decibels), and transition width (Ws-Wp, in hertz).
The primary advantage of IIR filters over FIR filters is that they typically meet a given set of specifications with a much lower filter order than a corresponding FIR filter. Although IIR filters have nonlinear phase, data processing within MATLAB is commonly performed “off-line,” that is, the entire data sequence is available prior to filtering. This allows for a noncausal, zero-phase filtering approach (via the filtfilt function), which eliminates the nonlinear phase distortion of an IIR filter. The classical IIR filters, Butterworth, Chebyshev Types I and II, elliptic, and Bessel, all approximate the ideal “brick wall” filter in different ways. This toolbox provides functions to create all these types of classical IIR filters in both the analog and digital domains (except Bessel, for which only the analog case is supported), and in lowpass, highpass, bandpass, and bandstop configurations. For most filter types, you can also find the lowest filter order that fits a given filter specification in terms of passband and stopband attenuation, and transition width(s).
The direct filter design function yulewalk finds a filter with magnitude response approximating a desired function. This is one way to create a multiband bandpass filter. You can also use the parametric modeling or system identification functions to design IIR filters. These functions are discussed in “Parametric Modeling” on page 4-15.
The generalized Butterworth design function maxflat is discussed in the section “Generalized Butterworth Filter Design” on page 2-15. The following table summarizes the various filter methods in the toolbox and lists the functions available to implement these methods.
IIR Filter Design
Filter Method Description Filter Functions
Analog Prototyping
Using the poles and zeros of a classical lowpass prototype filter in the continuous (Laplace) domain, obtain a digital filter through frequency transformation and filter discretization.
Complete design functions:
besself, butter, cheby1, cheby2, ellip
Order estimation functions:
buttord, cheb1ord, cheb2ord, ellipord
Lowpass analog prototype functions:
besselap, buttap, cheb1ap, cheb2ap, ellipap
Frequency transformation functions:
lp2bp, lp2bs, lp2hp, lp2lp
Filter discretization functions:
bilinear, impinvar
Direct Design Design digital filter directly in the discrete time-domain by approximating a piecewise linear magnitude response.
yulewalk
Generalized Butterworth Design
Design lowpass Butterworth filters with more zeros than poles.
maxflat
Parametric Modeling
Find a digital filter that approximates a prescribed time or frequency domain response. (See the System Identification Toolbox documentation for an extensive collection of parametric modeling tools.)
Time-domain modeling functions:
lpc, prony, stmcb
Frequency-domain modeling functions:
invfreqs, invfreqz
IIR Filter Design
Here are some example digital filters:
[b,a] = butter(5,0.4); % Lowpass Butterworth [b,a] = cheby1(4,1,[0.4 0.7]); % Bandpass Chebyshev Type I [b,a] = cheby2(6,60,0.8,'high'); % Highpass Chebyshev Type II [b,a] = ellip(3,1,60,[0.4 0.7],'stop'); % Bandstop elliptic
To design an analog filter, perhaps for simulation, use a trailing 's' and specify cutoff frequencies in rad/s:
[b,a] = butter(5,.4,'s'); % Analog Butterworth filter
All filter design functions return a filter in the transfer function, zero-pole-gain, or state-space linear system model representation, depending on how many output arguments are present.
Note All classical IIR lowpass filters are ill-conditioned for extremely low cut-off frequencies. Therefore, instead of designing a lowpass IIR filter with a very narrow passband, it can be better to design a wider passband and decimate the input signal.
This toolbox provides order selection functions that calculate the minimum filter order that meets a given set of requirements.
These are useful in conjunction with the filter design functions. Suppose you want a bandpass filter with a passband from 1000 to 2000 Hz, stopbands starting 500 Hz away on either side, a 10 kHz sampling frequency, at most 1 dB
Filter Type Order Estimation Function
Butterworth [n,Wn] = buttord(Wp,Ws,Rp,Rs)
Chebyshev Type I [n,Wn]^ = cheb1ord(Wp,^ Ws,^ Rp,^ Rs)
Chebyshev Type II [n,Wn] = cheb2ord(Wp, Ws, Rp, Rs)
Elliptic [n,Wn] = ellipord(Wp, Ws, Rp, Rs)
of passband ripple, and at least 60 dB of stopband attenuation. You can meet these specifications by using the butter function as follows. [n,Wn] = buttord([1000 2000]/5000,[500 2500]/5000,1,60)
n = 12 Wn = 0.1951 0.
[b,a] = butter(n,Wn);
An elliptic filter that meets the same requirements is given by [n,Wn] = ellipord([1000 2000]/5000,[500 2500]/5000,1,60)
n = 5 Wn = 0.2000 0.
[b,a] = ellip(n,1,60,Wn);
These functions also work with the other standard band configurations, as well as for analog filters.
The Chebyshev Type I filter minimizes the absolute difference between the ideal and actual frequency response over the entire passband by incorporating an equal ripple of Rp dB in the passband. Stopband response is maximally flat. The transition from passband to stopband is more rapid than for the Butterworth filter. H j( Ω) = 10 – Rp^ ⁄^20 at Ω = 1.
10 -1^100 0
1
Frequency(rad/sec)
Magnitude
IIR Filter Design
The Chebyshev Type II filter minimizes the absolute difference between the ideal and actual frequency response over the entire stopband by incorporating an equal ripple of Rs dB in the stopband. Passband response is maximally flat.
The stopband does not approach zero as quickly as the type I filter (and does not approach zero at all for even-valued filter order n). The absence of ripple in the passband, however, is often an important advantage. at.
H j( Ω) 10
10 -1^100 0
1
Frequency(rad/sec)
Magnitude
IIR Filter Design
Analog Bessel lowpass filters have maximally flat group delay at zero frequency and retain nearly constant group delay across the entire passband. Filtered signals therefore maintain their waveshapes in the passband frequency range. Frequency mapped and digital Bessel filters, however, do not have this maximally flat property; this toolbox supports only the analog case for the complete Bessel filter design function.
Bessel filters generally require a higher filter order than other filters for satisfactory stopband attenuation. at and decreases as filter order n increases.
Note The lowpass filters shown above were created with the analog prototype functions besselap, buttap, cheb1ap, cheb2ap, and ellipap. These functions find the zeros, poles, and gain of an order n analog filter of the appropriate type with cutoff frequency of 1 rad/s. The complete filter design functions (besself, butter, cheby1, cheby2, and ellip) call the prototyping functions as a first step in the design process. See ““Special Topics in IIR Filter Design” on page 2-44” for details.
H j( Ω) < 1 ⁄ 2 Ω = 1
10 -1^100 0
1
Frequency(rad/sec)
Magnitude
To create similar plots, use n = 5 and, as needed, Rp = 0.5 and Rs = 20. For example, to create the elliptic filter plot: [z,p,k] = ellipap(5,0.5,20); w = logspace(-1,1,1000); h = freqs(k*poly(z),poly(p),w); semilogx(w,abs(h)), grid
This toolbox uses the term direct methods to describe techniques for IIR design that find a filter based on specifications in the discrete domain. Unlike the analog prototyping method, direct design methods are not constrained to the standard lowpass, highpass, bandpass, or bandstop configurations. Rather, these functions design filters with an arbitrary, perhaps multiband, frequency response. This section discusses the yulewalk function, which is intended specifically for filter design; “Parametric Modeling” on page 4-15 discusses other methods that may also be considered direct, such as Prony’s method, Linear Prediction, the Steiglitz-McBride method, and inverse frequency design. The yulewalk function designs recursive IIR digital filters by fitting a specified frequency response. yulewalk’s name reflects its method for finding the filter’s denominator coefficients: it finds the inverse FFT of the ideal desired power spectrum and solves the “modified Yule-Walker equations” using the resulting autocorrelation function samples. The statement [b,a] = yulewalk(n,f,m)
returns row vectors b and a containing the n+1 numerator and denominator coefficients of the order n IIR filter whose frequency-magnitude characteristics approximate those given in vectors f and m. f is a vector of frequency points ranging from 0 to 1, where 1 represents the Nyquist frequency. m is a vector containing the desired magnitude response at the points in f. f and m can describe any piecewise linear shape magnitude response, including a multiband response. The FIR counterpart of this function is fir2, which also designs a filter based on an arbitrary piecewise linear magnitude response. See ““FIR Filter Design” on page 2-17” for details. Note that yulewalk does not accept phase information, and no statements are made about the optimality of the resulting filter.
For example, when the two orders are the same, maxflat is the same as butter: [b,a] = maxflat(3,3,0.25)
b = 0.0317 0.0951 0.0951 0.
a = 1.0000 -1.4590 0.9104 -0.
[b,a] = butter(3,0.25)
b = 0.0317 0.0951 0.0951 0.
a = 1.0000 -1.4590 0.9104 -0.
However, maxflat is more versatile because it allows you to design a filter with more zeros than poles: [b,a] = maxflat(3,1,0.25)
b = 0.0950 0.2849 0.2849 0.
a = 1.0000 -0.
The third input to maxflat is the half-power frequency, a frequency between 0 and 1 with a desired magnitude response of. You can also design linear phase filters that have the maximally flat property using the 'sym' option: maxflat(4,'sym',0.3)
ans = 0.0331 0.2500 0.4337 0.2500 0.
For complete details of the maxflat algorithm, see Selesnick and Burrus [2].
FIR Filter Design
Digital filters with finite-duration impulse response (all-zero, or FIR filters) have both advantages and disadvantages compared to infinite-duration impulse response (IIR) filters. FIR filters have the following primary advantages:
The primary disadvantage of FIR filters is that they often require a much higher filter order than IIR filters to achieve a given level of performance. Correspondingly, the delay of these filters is often much greater than for an equal performance IIR filter.
Filter Method Description Filter Functions
Windowing Apply window to truncated inverse Fourier transform of desired “brick wall” filter
fir1, fir2, kaiserord
Multiband with Transition Bands
Equiripple or least squares approach over sub-bands of the frequency range
firls, firpm, firpmord
Constrained Least Squares
Minimize squared integral error over entire frequency range subject to maximum error constraints
fircls, fircls
Arbitrary Response
Arbitrary responses, including nonlinear phase and complex filters
cfirpm
Raised Cosine Lowpass response with smooth, sinusoidal transition
firrcos
FIR Filter Design
Consider the ideal, or “brick wall,” digital lowpass filter with a cutoff frequency of ω 0 rad/s. This filter has magnitude 1 at all frequencies with magnitude less than ω 0 , and magnitude 0 at frequencies with magnitude between ω 0 and π. Its impulse response sequence h(n) is
This filter is not implementable since its impulse response is infinite and noncausal. To create a finite-duration impulse response, truncate it by applying a window. By retaining the central section of impulse response in this truncation, you obtain a linear phase FIR filter. For example, a length 51 filter with a lowpass cutoff frequency ω 0 of rad/s is
b = 0.4sinc(0.4(-25:25));
The window applied here is a simple rectangular window. By Parseval’s theorem, this is the length 51 filter that best approximates the ideal lowpass filter, in the integrated least squares sense. The following command displays the filter’s frequency response in FVTool:
fvtool(b,1)
Note that the y-axis shown in the figure below is in Magnitude Squared. You can set this by right-clicking on the axis label and selecting Magnitude Squared from the menu.
h n( )
2 π
------ (^) H (ω )ejωn^ dω
π
2 π
------ (^) ejωn^ dω
ω 0
ω 0 π
-------sinc
ω 0 π = = = ( -------n)
0.4π
Ringing and ripples occur in the response, especially near the band edge. This “Gibbs effect” does not vanish as the filter length increases, but a nonrectangular window reduces its magnitude. Multiplication by a window in the time domain causes a convolution or smoothing in the frequency domain. Apply a length 51 Hamming window to the filter and display the result using FVTool: b = 0.4sinc(0.4(-25:25)); b = b.*hamming(51)'; fvtool(b,1)