Bandpass FIR
Design bandpass finite impulse response filter
Description
A bandpass filter attenuates the energy of an input signal outside a specified frequency range. A finite impulse response (FIR) filter computes an output signal as a running weighted average of input samples.
Signal Processing Toolbox™ provides different ways to design bandpass FIR filters:
designfiltfunction — Design a bandpass FIR filter at the command line or in a script. Use"bandpassfir"as the first argument when you call the function.For an example, see Design Bandpass FIR Filter Using designfilt.
Design Filter Live Editor task — Design a bandpass FIR filter as part of a live script. The task displays code that you can paste into other MATLAB® programs.
For an example, see Design Bandpass FIR Filter Using Live Editor Task.
Filter Designer app — Design a bandpass FIR filter interactively. Export your design to the MATLAB workspace, to Simulink®, or to a file.
For an example, see Design Bandpass FIR Filter Using Filter Designer.
All of these methods return digitalFilter objects. If you
have a DSP System Toolbox™ license, you can generate your design as a filter System object™ and include additional Design Method Options.
For other ways to design bandpass FIR filters using MATLAB, see Other Bandpass FIR Filter Design Functions.
Examples
To design the filter at the command line or in a script, use the designfilt function with "bandpassfir" as the first argument. Use name-value arguments to specify your design further.
d = designfilt("bandpassfir", ... % Filter type SampleRate=2000, ... % Sample rate FilterOrder=30, ... % Filter order StopbandFrequency1=300,PassbandFrequency1=350, ... % Frequency constraints PassbandFrequency2=550,StopbandFrequency2=750, ... DesignMethod="ls", ... % Design method StopbandWeight1=3,PassbandWeight=1,StopbandWeight2=5); % Design method options filterAnalyzer(d)

To design the filter using the Design Filter Live Editor task:
Specify the filter:
Under Select filter response, select Bandpass FIR.
Under Sample Rate, specify Frequency units as
Hzand Input sample rate (Hz) as2000.Under Specify filter order, set Order mode to
Specifyand enter a value of30.Under Specify frequency parameters, specify:
Stopband frequency 1 as
300HzPassband frequency 1 as
350HzPassband frequency 2 as
550HzStopband frequency 2 as
750Hz
Under Specify algorithm, select
FIR least-squares. Under Specify algorithm options, specify:Stopband weight 1 as
3Passband weight as
1Stopband weight 2 as
5
The Live Editor task updates the filter automatically by default.

To design the filter using the Filter Designer app:
In the Response gallery of the Designer tab in the app toolstrip, select Bandpass FIR.
Specify the filter using the options in the Filter Parameters table:
In Design by, select Specification.
In Sample Rate, specify Frequency units as
Hzand Input sample rate (Hz) as2000.Under Filter Order, set Order mode to
Specifyand enter a value of30.Under Frequency Specifications, specify:
Stopband frequency 1 as
300HzPassband frequency 1 as
350HzPassband frequency 2 as
550HzStopband frequency 2 as
750Hz
Under Algorithm, select
FIR least-squares. Under Algorithm Options, specify:Stopband weight 1 as
3Passband weight as
1Stopband weight 2 as
5
In the Filter section of the Designer tab, click Update Filter.

Export code to create your digital filter. On the toolstrip, click Export and select
Generate MATLAB function>Digital Filter Object. The code appears in the editor.function designedFilter = bandpassfir1filt designedFilter = designfilt('bandpassfir', ... 'FilterOrder',30,'StopbandFrequency1',300, ... 'PassbandFrequency1',350,'PassbandFrequency2',550, ... 'StopbandFrequency2',750,'SampleRate',2000, ... 'DesignMethod','ls','StopbandWeight1',3, ... 'StopbandWeight2',5); end
Parameters
Design Method
Specify the algorithm to design the filter. The available design methods correlate with the set of design specifications that you choose.
Design the filter using the Parks-McClellan algorithm. Equiripple filters have a frequency response that minimizes the maximum ripple magnitude over all bands.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify
| In the Specify algorithm section of the
task, set Design method to
| In the Algorithm section of the filter
parameters panel, set Design method to
|
The equiripple design method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
| N/A |
|
| N/A | |
| N/A |
|
|
| ✓ |
|
| N/A |
| |
|
| N/A |
| ✓ |
|
|
|
| ✓ |
Design the filter using the Kaiser window algorithm. The method truncates the impulse response of an ideal filter and uses a Kaiser window to attenuate the resulting truncation oscillations.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify
| In the Specify algorithm section of the
task, set Design method to | In the Algorithm section of the filter
parameters panel, set Design method to
|
The Kaiser window design method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
| N/A |
|
|
|
Design the filter using the window algorithm. The method uses a least-squares approximation to compute the filter coefficients and then smooths the impulse response with Window.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify
| In the Specify algorithm section of the
task, set Design method to
| In the Algorithm section of the filter
parameters panel, set Design method to
|
The window design method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
|
| N/A |
|
Design the filter using the constrained least-squares algorithm. The method minimizes the discrepancy between a specified arbitrary piecewise-linear function and the magnitude response of the filter. At the same time, it lets you set constraints on the passband ripple and the stopband attenuation.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify | In the Specify algorithm section of the
task, set Design method to | In the Algorithm section of the filter
parameters panel, set Design method to
|
The constrained least-squares design method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
|
|
|
|
Design the filter using the least-squares algorithm. The method minimizes the discrepancy between a specified arbitrary piecewise-linear function and the filter’s magnitude response.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify | In the Specify algorithm section of the
task, set Design method to | In the Algorithm section of the filter
parameters panel, set Design method to
|
The least-squares design method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
|
| N/A |
|
Design the filter using the least Pth-norm unconstrained optimization algorithm.
You must have a DSP System Toolbox license to use this design method.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
Specify
| In the Specify algorithm section of
the task, set Design method to | In the Algorithm section of the filter
parameters panel, set Design method to
|
The least Pth-norm method supports these design parameter combinations.
| Filter Order | Frequency Specifications | Magnitude Specifications | Design Method Options | DSP System Toolbox License Required |
|---|---|---|---|---|
|
| N/A |
| ✓ |
Sample Rate
Specify the filter sample rate as a positive scalar expressed in hertz.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
| In the Sample Rate section of the task:
| In the Sample Rate section of the filter parameters panel:
|
Filter Order
Specify the filter order N as a positive integer. Some design methods let you specify the order. Others generate minimum-order designs, which are the shortest filters that satisfy the specified constraints.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
| In the Specify Filter Order section of the task:
| In the Filter Order section of the filter parameters panel:
|
Frequency Specifications
Specify the lower stopband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The lower stopband frequency is the highest frequency in the lower stopband for which the magnitude response of the filter is at least Stopband Attenuation 1 dB lower than the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the lower cutoff frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The lower cutoff frequency is the lowest frequency at which the magnitude response
of the filter is mag2db(1/2)= 20 log10½ = –6.02
dB below the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the lower passband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The lower passband frequency is the lowest frequency in the passband for which the magnitude response of the filter is within an interval of width Passband Ripple about the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the higher passband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The higher passband frequency is the highest frequency in the passband for which the magnitude response of the filter is within an interval of width Passband Ripple about the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the higher cutoff frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The higher cutoff frequency is the highest frequency at which the magnitude
response of the filter is mag2db(1/2)= 20 log10½ = –6.02
dB below the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the higher stopband frequency as a positive scalar smaller than the Nyquist frequency. If you work with normalized frequencies, the Nyquist frequency is 1. If you specify a sample rate Fs, the Nyquist frequency is Fs/2.
The higher stopband frequency is the lowest frequency in the higher stopband for which the magnitude response of the filter is at least Stopband Attenuation 2 dB lower than the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Magnitude Specifications
Specify the lower stopband attenuation as a positive scalar in decibels.
The lower stopband attenuation measures the extent by which the filter gain in the lower stopband is decreased in comparison to the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the passband ripple as a positive scalar in decibels.
The passband ripple measures the fluctuation of the passband gain of the filter about the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Specify the higher stopband attenuation as a positive scalar in decibels.
The higher stopband attenuation measures the extent by which the filter gain in the higher stopband is decreased in comparison to the reference value, usually 0 dB.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Use this argument to constrain the attenuation of the lower stopband for an Equiripple design.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Use this argument to constrain the ripple in the passband for an Equiripple design.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Use this argument to constrain the attenuation of the higher stopband for an Equiripple design.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Design Method Options
Basic Options
Minimum order parity of a Kaiser Window design or an Equiripple design, specified as one of these options:
Any — The returned filter can have even or odd order, whichever is smaller.
Even — The returned filter has the smallest possible even order.
Odd — The returned filter has the smallest possible odd order. This option is available only for equiripple designs.
You must have a DSP System Toolbox license to use this option with the equiripple method.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Passband offset for a Constrained Least Squares design, specified as a positive scalar in decibels. This parameter specifies the filter gain in the passband. For example:
Setting this parameter to
2results in a filter with a passband gain of 2 dB or 1.259.Setting this parameter to
0results in a filter with unit gain in the passband.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Passband optimization weight for an Equiripple, Least Squares, or Least Pth-Norm design, specified as a positive scalar.
Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopband are equally weighted, each with unit weight. By increasing the passband weight, you can decrease the passband ripple at the expense of decreasing stopband attenuation.
You must have a DSP System Toolbox license to use this option with some syntaxes.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Scale passband when using the Kaiser Window design method or the Window design method,
specified as a logical scalar. When you set this parameter to true,
the passband is scaled, after windowing, so that the filter has unit gain at zero
frequency.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Lower stopband optimization weight for an Equiripple, Least Squares, or Least Pth-Norm design, specified as a positive scalar.
Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopbands are equally weighted, each with unit weight. By increasing a stopband weight, you can increase the attenuation of a stopband at the expense of increasing the passband ripple.
You must have a DSP System Toolbox license to use this option with some syntaxes.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Higher stopband optimization weight for an Equiripple, Least Squares, or Least Pth-Norm design, specified as a positive scalar.
Weights are a way of specifying the relative importance of the passband ripple and the stopband attenuation in a filter design. By default, the passband and the stopbands are equally weighted, each with unit weight. By increasing a stopband weight, you can increase the attenuation of a stopband at the expense of increasing the passband ripple.
You must have a DSP System Toolbox license to use this option with some syntaxes.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Window used by the Window algorithm, specified as one of these options:
Hamming (@
hamming)Hann (@
hann)Kaiser (@
kaiser) — Specify the shape factor as a positive real scalar.Rectangular (@
rectwin)Chebyshev (@
chebwin) — Specify the sidelobe magnitude factor as a positive scalar in decibels.Bartlett (@
bartlett)Blackman (@
blackman)Flat top (@
flattopwin)Gaussian (@
gausswin) — To use a Gaussian window with a width factor α ≠ 2.5 in the Filter Designer app or the Design Filter Live Editor task, specify it as a custom window.Nuttall (@
nuttallwin)Triangular (@
triang)Custom — Specify a custom window as a vector of length N + 1, where N is the Filter Order. You can also specify the custom window as a function name or a function handle with N + 1 as first input. Additional inputs can be passed by specifying a cell array.
Example: hann(N+1) and
(1-cos(2*pi*(0:N)'/N))/2 both specify a Hann window to use with a
filter of order N.
Example: "hamming" specifies a Hamming window of the required
order.
Example: @hann specifies a Hann window of the required
order.
Example: {@kaiser,0.5} specifies a Kaiser window of the required
order with shape parameter 0.5.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Zero phase for a Constrained Least Squares design, specified
as logical scalar. When you set this parameter to true, the
zero-phase response of the filter is always positive, enabling you to perform spectral
factorization on the result and obtain a minimum-phase filter from it.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Advanced Options
Density of the frequency grid used by the Least Pth-Norm algorithm, specified as a positive scalar ≥ 10. The frequency grid has roughly (Density Factor × Filter Order)/(2 × Passband Frequency) frequency points. Increasing the density factor results in filters that more closely approximate an equiripple filter but take longer to compute.
You must have a DSP System Toolbox license to use this option. This parameter is available only in the
designfilt function.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
| N/A | N/A |
Initial Pth norm used by the Least Pth-Norm algorithm, specified as a positive scalar. Starting the optimization with a smaller initial value aids in the convergence of the algorithm. For more information, see Least Pth-Norm Optimal IIR Filter Design.
You must have a DSP System Toolbox license to use this option. This parameter is available only in the
designfilt function.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
| N/A | N/A |
Initial estimate of the filter numerator coefficients for the Least Pth-Norm algorithm, specified as a vector of size (N+1)-by-1, where N is the Filter Order that you specify.
You must have a DSP System Toolbox license to use this option. This parameter is available only in the
designfilt function.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
| N/A | N/A |
L-infinity norm used by the Least Pth-Norm algorithm, specified as a positive scalar.
You must have a DSP System Toolbox license to use this option.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
Phase constraint for an Equiripple or Least Pth-Norm design, specified as one of these options:
Linear — Design a linear-phase equiripple FIR filter.
Minimum — Design a minimum-phase equiripple FIR filter.
Maximum — Design a maximum-phase equiripple FIR filter.
You must have a DSP System Toolbox license to use this option.
designfilt Function | Design Filter Live Editor Task | Filter Designer App |
|---|---|---|
|
|
|
More About
Use one of these functions to design a bandpass FIR filter:
fir1— Window-based FIR filter designfir2— Frequency sampling-based FIR filter designfirls— Least-squares linear-phase FIR filter designfircls— Constrained-least-squares FIR multiband filter designfirpm— Parks-McClellan optimal FIR filter designcfirpm— Complex and nonlinear-phase equiripple FIR filter designfirgr— Generalized Remez FIR filter designfirlpnorm— Least P-norm optimal FIR filterdesignBandpassFIR— Design and implement bandpass FIR filter
Use this function to bandpass-filter a signal:
bandpass— Bandpass-filter signals
See Also
Apps
Functions
Live Editor Tasks
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)