Basic Filter Design Process
Use the following two steps to design a simple filter.
Example — Design a Filter in Two Steps
Assume that you want to design a bandpass filter. Typically a bandpass filter is defined as shown in the following figure.
In this example, a sampling frequency of Fs = 48 kHz is used. This bandpass filter has the following specifications, specified here using MATLAB code:
A_stop1 = 60; % Attenuation in the first stopband = 60 dB
F_stop1 = 8400; % Edge of the stopband = 8400 Hz
F_pass1 = 10800; % Edge of the passband = 10800 Hz
F_pass2 = 15600; % Closing edge of the passband = 15600 Hz
F_stop2 = 18000; % Edge of the second stopband = 18000 Hz
A_stop2 = 60; % Attenuation in the second stopband = 60 dB
A_pass = 1; % Amount of ripple allowed in the passband = 1 dB
In the following two steps, these specifications are passed to the fdesign.bandpass method as parameters. For more information about passing specifications to the fdesign filter specification object, refer to the reference.
- Step 1
To create a filter specification object, evaluate the following code at the MATLAB prompt:
d = fdesign.bandpass
Now, pass the filter specifications that correspond to the default Specification — fst1,fp1,fp2,fst2,ast1,ap,ast2. This example adds fs as the final input argument to specify the sampling frequency of 48 kHz.
>> BandPassSpecObj = ...
fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2', ...
F_stop1, F_pass1, F_pass2, F_stop2, A_stop1, A_pass, ...
A_stop2, 48000)
BandPassSpecObj =
Response: 'Bandpass'
Specification: 'Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2'
Description: {7x1 cell}
NormalizedFrequency: false
Fs: 48000
Fstop1: 8400
Fpass1: 10800
Fpass2: 15600
Fstop2: 18000
Astop1: 60
Apass: 1
Astop2: 60Note The order of the filter is not specified, allowing a degree of freedom for the algorithm design in order to achieve the specification. The design will be a minimum order design.
The specification parameters, such as Fstop1, are all given default values when none are provided. You can change the values of the specification parameters after the filter specification object has been created. For example, if there are two values that need to be changed, Fpass2 and Fstop2, use the set command, which takes the object first, and then the parameter value pairs. Evaluate the following code at the MATLAB prompt:
>> set(BandPassSpecObj, 'Fpass2', 15800, 'Fstop2', 18400)
BandPassSpecObj is the new filter specification object which contains all the required design parameters, including the filter type.
You may also change parameter values in filter specification objects by accessing them as if they were elements in a struct array.
>> BandPassSpecObj.Fpass1=15800;
- Step 2
Design the filter by using the design command. You can access the design methods available for you specification object by calling the designmethods function. For example, in this case, you can execute the command
>> designmethods(BandPassSpecObj)
Design Methods for class
fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2):
butter
cheby1
cheby2
ellip
equiripple
kaiserwinAfter choosing a design method use, you can evaluate the following at the MATLAB prompt (this example assumes you've chosen 'equiripple'):
>> BandPassFilt = design(BandPassSpecObj, 'equiripple')
BandPassFilt =
FilterStructure: 'Direct-Form FIR'
Arithmetic: 'double'
Numerator: [1x44 double]
PersistentMemory: false
Note If you do not specify a design method, a default method will be used. For example, you can execute the command
>> BandPassFilt = design(BandPassSpecObj)
BandPassFilt =
FilterStructure: 'Direct-Form FIR'
Arithmetic: 'double'
Numerator: [1x44 double]
PersistentMemory: falseand a design method will be selected automatically.
To check your work, you can plot the filter magnitude response using the Filter Visualization tool. Verify that all the design parameters are met:
>> fvtool(BandPassFilt) %plot the filter magnitude response
Using Filterbuilder to Design a Filter
Filterbuilder presents the option of designing a filter using a GUI dialog box as opposed to the command line instructions. You can use Filterbuilder to design the same bandpass filter designed in the previous section, Basic Filter Design Process
Example — Using Filterbuilder to Design a Simple Filter
To design the filter using FilterBuilder:
Type the following at the MATLAB prompt:
filterbuilder
The following dialog box opens:
Select Bandpass filter response from the list in the dialog box, and hit the OK button. The following dialog box opens:
Enter the correct frequencies for Fpass2 and Fstop2, as shown in the preceding figure, then click OK. Here the specification uses normalized frequency, so that the passband and stopband edges are expressed as a fraction of the Nyquist frequency (in this case, 48/2 kHz). The following message appears at the MATLAB prompt:
The variable 'Hbp' has been exported to the command window.
If you display the Workspace tab, as shown in the following figure, you see the object Hbp has been placed on your workspace.
To check your work, plot the filter magnitude response using the Filter Visualization tool. Verify that all the design parameters are met:
fvtool(Hbp) %plot the filter magnitude response
matlab code to generate parameters for a bandpass filter pls help me
ReplyDelete