Filters Two Design With Matlab
Filters Two Design With Matlab
The objective of this experiment is to gain some experience in designing filters with desired specifications. You will work with a number of tools helping you in designing filters in MATLAB.
Figure P1 The alteration of frequency components of a signal input to a filter Simple filters can be categorized into four major categories: lowpass, highpass, bandpass and bandstop (or band-reject). Figure P3 shows the ideal forms of these four filters in the frequency domain. As the name suggests a lowpass filter for instance, passes the low frequency components of a signal while blocking the high frequency ones. As you have learned the convolution operation in time domain is equivalent to multiplication in frequency domain. Thus, multiplying the frequency domain representation of the input signal with that of the filter, high frequency components of the input signal will be multiplied in zero and would thus vanish, while the lower frequency components will be multiplied by one and would pass without any change.
Noise
f Interfering stations
Desired station
Figure P2 Some basic applications of filters: top) noise reduction by removing out of band (high frequency noise), bottom) removing interfering signals: passing of a tuned channel in a radio. In this experiment you will learn how to use some tools in MATLAB signal processing toolbox to design filters with your desired characteristics.
Figure P3 The ideal frequency response of the four basic filter types: 1) lowpass, 2) highpass, 3) bandpass and 4) bandstop (or band-reject)
Some figures that you should know without using your calculator are 3 dB and its multiples. 3 dB is almost equal to 2, thus if you have a quantity that is 3 dB greater than another, it is actually two times greater than it. (Note that you are using logarithm, thus addition of the logarithms is equivalent to multiplication of the numbers themselves.) By analogy, -3 dB, 6 dB and -6 dB are equivalent to 0.5, 4 and 0.25 respectively. Passband Parameters The passband of the ideal filter is the band of frequencies where the filter frequency response is not zero. If a signals frequency content lies in this band, the signal will pass without any alteration. In case of practical filters, the frequency response does not have an abrupt change from zero to one or the value in passband (Fig P4). Instead, there is a transition from a higher level to a lower level. Hence, for a practical filter the band of frequencies over which the magnitude of frequency response is greater than a threshold is called the passband. This threshold is usually set at -3 dB of the maximum magnitude in passband. The frequency at which the filters frequency response magnitude reaches this threshold is called the cut-off frequency of the filter ( f c ) . If the frequency response does not decrease monotonically in the passband the filter is said to have ripples in the passband. The difference between the maximum and minimum magnitude values in the passband defines the passband ripple factor R p usually given in dB. The maximum value of the magnitude in passband is called the gain of the filter. Stopband Parameters The stopband of the ideal filter is the band of frequencies where the filter frequency response is zero. Thus the frequency components of the signal lying in this band will not
pass and will be fully removed. Again, since the transition from high to low is not abrupt in practical filters, a threshold level defines this region. So, the band of frequencies, where the magnitude of the frequency response of the filter drops below a threshold level is called stopband. The threshold value is dependent on the application of the filter usually about 40 dB and is usually denoted by As or Rs . If there are ripples in the stopband, the maximum value of the magnitude of frequency response in the stopband shall lie below the threshold. The frequency at which the magnitude of the filter response first falls below the threshold value is called the stopband frequency denoted by f s .
Figure P4 The filter parameters: 1) passband, 2) stopbands, 3) cut-off frequencies, 4) stopband frequencies, 5) passband ripple, 6) stopband level, 7) filter gain.
Butterworth Filter The Butterworth filter of order N , also called the maximally flat filter, is an approximation of the ideal filter, which the first 2 N 1 derivatives of its magnitude squared are zero. As a result the frequency response of this filter decreases monotonically with frequency and H ( f = f c ) = 1 2 . The decrease is very slow in the passband and quick in the stopband. In a design problem where no ripple is acceptable in passband and stopband, Butterworth filter is a good choice.
Figure P5 The frequency response of a Butterworth filter with c = 1 Chebychev Type I Filter A Chebychev type I approximates the ideal filter by minimizing the absolute difference between the resulting filter and the ideal filter, over the passband. This filter results in appearance of ripples in the passband. The ripples have a constant magnitude of R p which is one of the design parameters of this filter. The stopband response is maximally flat. The transition from passband to stopband occurs faster than the Butterworth filter: H ( f = f c ) = R p . If the ripples in the passband are acceptable, a Chebychev filter usually require a lower-order transfer function than a Butterworth filter for the same specifications.
Chebychev Type II Filter A Chebychev type I approximates the ideal filter by minimizing the absolute difference between the resulting filter and the ideal filter, over the stopband. This filter results in appearance of ripples in the stopband. The ripples have a constant magnitude of Rs which is one of the design parameters of this filter. The passband response is maximally flat and H ( f = f c ) = Rs . The transition from passband to stopband occurs slower than the type I filter and for even filter order, it never reaches zero. Its advantage over type I is the absence of ripples in the passband.
Figure P7 The frequency response of a Chebychev type II filter with s = 1 Elliptic Filter The elliptic filter results in the steepest transition from passband to stopband by allowing ripples in both passband and stopband. This filter usually satisfies the desired filter specifications with the lowest order among the four types studied. The passband and stopband ripples R p and Rs are also required as design parameters.
Click the play sound in the toolbar to listen to the output. Switch the selected trace from output to input, play the signals and note the difference. Now go back to filter design screen to compare different filter design methods with each other. Make sure the value of R p is set at 3 dB and Rs at 20 dB.
Note the shape of the Butterworth filter response and specifically the stopband frequencies. Now change the filter type to Chebychev type I. Take note of the actual stopband frequencies and the shape of the filter response. Repeat for the Chebychev type II and elliptic filter types. What is your deduction?
To view the impulse response of each filter, go back to sptool main window and select your filter and click the View button. A new tool window appears. You may see the phase and amplitude response of the filter you have designed in this window. From the left panel, check the Impulse Response. Use the zoom tool , to zoom in and see the first portion
of the response. Use the zoom all tool , to select another potion or use the zoom tool to zoom in again. Uncheck the Magnitude and Phase boxes and check the Zeros and Poles. Zoom out to see the full plot. In the design window, change the filter type. What happens to the position of the poles and zeros? Can you compare the four basic designs? 2. Out of Band Noise Removal In this part you will use a lowpass filter to remove the high frequency noise in a signal. At MATLAB command prompt use size command to determine the number of samples in the downsampled French speaker sound you loaded before. Generate a random noise vector n with the same number of samples as the French speakers signal. Use MATLAB randn command to generate the noise vector whose samples have Gaussian probability distribution. Scale down the noise by multiplying your vector by 0.1. Add the noise and your original sound to make a new vector. Make sure you dont destroy your original sound file. Import the noise and the noisy sound in sptool. View the noise, noisy sound and the original sound using View button. Listen to the three signals. Now design a lowpass filter with following specifications: o f c = 1500 Hz and f s = 1650 Hz. o No ripple in passband is allowed. o Your filter order should not be more than 15. (Check the right panel to see the order of your filter) o Rs should be at least 30 dB. Apply your filter to the noise signal and to the noise. View the results and signals before filtering. Listen to them and compare them. Now try to export your filter design to MATLAB: In sptool main window in File menu select Export Select your filter name in the left panel To see the transfer function of the filter, check the Export Filter as TF Object.
Click the Export to worksapce button. At MATLAB command prompt, type the name of your filter design to see its transfer function. You will see the name of your filter in MATLABs workspace panel. Return to sptool and again export your filter design now with the Export Filter as TF Object unchecked. Confirm replacement of your old workspace filter export. At MATLAB command prompt, type the name of your filter you should see something like this:
filt2 = tf: ss: zpk: sos: imp: step: t: H: G: f: specs: Fs: type: lineinfo: SPTIdentifier: label: [1x1 struct] [] [1x1 struct] [] [] [] [] [1x4096 double] [4096x1 double] [1x4096 double] [1x1 struct] 11025 'design' [1x1 struct] [1x1 struct] 'filt2'
You will see the name of your filter instead of filt2. To access the transfer function parameters of your filter use this syntax and replace filt2 with your filters name: filt2.tf.num to see the numerator coefficients of your filter and filt2.tf.den to see its denominator coefficients. You may access the other parameters of the filter, like location of poles and zeros and sampling frequency in the same way.