| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Filter Design Toolbox |
| Contents | Index |
| Learn more about Filter Design Toolbox |
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.
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: 60 Note 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.Fpass2=15800;
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 kaiserwin
After 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: false and 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

![]() | Filter Design Process Overview | Using Filterbuilder to Design a Filter | ![]() |

Learn how to apply early verification to your development process through these technical resources.
How much time do you spend on testing to ensure implementation meets system-level requirements?
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |