designHalfbandFIR
Description
designs a halfband
FIR equiripple filter with the filter order of 24 and the transition width of 0.1.
B
= designHalfbandFIRB
is a vector of halfband FIR coefficients of length 25.
The System object™ argument is false
by default. To implement the filter,
assign the filter coefficients in B
to one of the supported System
objects.
specifies options using one or more name-value arguments.B
= designHalfbandFIR(Name=Value
)
For example,
designs a halfband FIR filter with the filter order of 30 and transition width of 0.2 by
using the Kaiser window design method. As the B
=
designHalfbandFIR
(FilterOrder
=30,TransitionWidth
=0.2,DesignMethod
="kaiser",SystemObject
=true)SystemObject
argument
is true
, the function designs and implements the halfband FIR filter.
B
is a dsp.FIRFilter
System object in this case.
When you specify only a partial list of filter parameters, the function designs the filter by setting the other design parameters to their default values.
The function supports three design methods. Each design method supports a specific
set of design combinations. For more information, see DesignMethod
.
This function supports code generation under certain conditions. For more information, see Code Generation.
Examples
Design and Implement Equiripple FIR Halfband Filter
Design an equiripple FIR halfband filter with the order of 24 and a transition width of 0.1 using the designHalfbandFIR
function. Assign the filter coefficients to a dsp.FIRFilter
System object.
b = designHalfbandFIR(FilterOrder=24,DesignMethod='equiripple');
hbFIR = dsp.FIRFilter(b);
Create a dsp.DynamicFilterVisualizer
object and visualize the magnitude response of the filter.
dfv = dsp.DynamicFilterVisualizer(NormalizedFrequency=true); dfv(hbFIR);
Create a spectrumAnalyzer
object to visualize the spectra of the input and output signals.
scope = spectrumAnalyzer(SampleRate=2, PlotAsTwoSidedSpectrum=false,... ChannelNames=["Input Signal","Filtered Signal"]);
Stream in random data and filter the signal using the FIR halfband filter.
for i = 1:1000 x = randn(1024, 1); y = hbFIR(x); scope(x,y); end
Design and Implement FIR Halfband Interpolator
Design an equiripple FIR halfband interpolator object of order 48 using the designHalfbandFIR
function. Set the Verbose
argument to true
.
hbFIR = designHalfbandFIR(FilterOrder=48,SystemObject=true,... Structure='interp',Verbose=true)
designHalfbandFIR(FilterOrder=48, TransitionWidth=0.1, DesignMethod="equiripple", Passband="lowpass", Structure="interp", SystemObject=true)
hbFIR = dsp.FIRHalfbandInterpolator with properties: Specification: 'Coefficients' Numerator: [0 -0.0082 0 0.0079 0 -0.0116 0 0.0165 0 -0.0227 0 0.0309 0 -0.0419 0 0.0571 0 -0.0800 0 0.1193 0 -0.2073 0 0.6350 1 0.6350 0 -0.2073 0 0.1193 0 -0.0800 0 0.0571 0 -0.0419 0 0.0309 0 -0.0227 0 0.0165 0 -0.0116 ... ] (1x49 double) FilterBankInputPort: false Use get to show all properties
Create a dsp.DynamicFilterVisualizer
object and visualize the magnitude response of the filter.
dfv = dsp.DynamicFilterVisualizer(NormalizedFrequency=true); dfv(hbFIR);
The input is a cosine wave with an angular frequency of radians/sample.
input = cos(pi/4*(0:39)');
Interpolate the cosine signal using the FIR halfband interpolator.
output = hbFIR(input);
Plot the original and interpolated signals. In order to plot the two signals on the same plot, you must account for the output delay introduced by the FIR halfband interpolator and the scaling introduced by the filter. Use the outputDelay
function to compute the delay
value introduced by the interpolator. Shift the output by this delay value.
Visualize the input and the resampled signals. The input and output values coincide every other sample due to the interpolation factor of 2.
[delay,FsOut] = outputDelay(hbFIR,FsIn=1)
delay = 12
FsOut = 2
nInput = (0:length(input)-1); tOutput = (0:length(output)-1)/FsOut-delay; stem(tOutput,output,'filled',MarkerSize=4); hold on; stem(nInput,input); hold off; xlim([-5,20]) legend('Interpolated by 2','Input signal','Location','best');
Design and Implement FIR Halfband Decimator
Design an equiripple FIR halfband decimator object of order 48 using the designHalfbandFIR
function. Set the Verbose
argument to true
.
hbFIR = designHalfbandFIR(FilterOrder=48,SystemObject=true,... Structure='decim',Verbose=true)
designHalfbandFIR(FilterOrder=48, TransitionWidth=0.1, DesignMethod="equiripple", Passband="lowpass", Structure="decim", SystemObject=true)
hbFIR = dsp.FIRHalfbandDecimator with properties: Main Specification: 'Coefficients' Numerator: [0 -0.0041 0 0.0040 0 -0.0058 0 0.0082 0 -0.0114 0 0.0155 0 -0.0209 0 0.0286 0 -0.0400 0 0.0597 0 -0.1037 0 0.3175 0.5000 0.3175 0 -0.1037 0 0.0597 0 -0.0400 0 0.0286 0 -0.0209 0 0.0155 0 -0.0114 0 0.0082 0 -0.0058 0 0.0040 0 -0.0041 0] Use get to show all properties
Create a dsp.DynamicFilterVisualizer
object and visualize the magnitude response of the filter.
dfv = dsp.DynamicFilterVisualizer(NormalizedFrequency=true); dfv(hbFIR);
The input is a cosine wave with an angular frequency of radians/sample.
input = cos(pi/4*(0:39)');
Decimate the cosine signal using the FIR halfband decimator.
output = hbFIR(input);
Plot the original and decimated signals. In order to plot the two signals in the same plot, you must account for the output delay of the FIR halfband decimator and the scaling introduced by the filter. Use the outputDelay
function to compute the delay
introduced by the decimator. Shift the output by this delay value.
Visualize the input and the resampled signals. After a short transition, the output converges to a cosine of frequency , as expected, which is twice the frequency of the input signal, . Due to the decimation factor of 2, the output samples coincide with every other input sample.
[delay,FsOut] = outputDelay(hbFIR,FsIn=1)
delay = 24
FsOut = 0.5000
nInput = (0:length(input)-1); tOutput = (0:length(output)-1)/FsOut-delay; stem(tOutput,output,'filled',MarkerSize=4); hold on; stem(nInput,input); hold off; xlim([-10,15]) legend('Decimated by 2','Input signal','Location','best');
Input Arguments
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example:
designHalfbandFIR(FilterOrder=30,TransitionWidth=0.3,Passband='lowpass')
FilterOrder
— Order of halfband FIR filter
24
(default) | even nonnegative integer
Order of the halfband FIR filter, N, specified as an even nonnegative integer.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
TransitionWidth
— Transition width of halfband FIR filter
0.1
(default) | scalar in the range (0
,1
]
Transition width of the halfband FIR filter, TW,
specified as a normalized scalar in the range
(0
,1
].
Data Types: single
| double
StopbandAttenuation
— Stopband attenuation of halfband FIR filter
60
(default) | positive scalar
Stopband attenuation of the halfband FIR filter, Ast, specified as a positive scalar in dB units.
Data Types: single
| double
DesignMethod
— Window design method
'auto'
(default) | 'kaiser'
| 'equiripple'
| 'ls'
Window design method, specified as one of these options:
'auto'
–– When you do not specify a window design method or specify'auto'
, the function automatically chooses the best design method for the given specification parameters.'kaiser'
–– Kaiser method supports all the design specification combinations the function supports.Here is the list:
FilterOrder
andTransitionWidth
(N,TW)FilterOrder
andStopbandAttenuation
(N,Ast)TransitionWidth
andStopbandAttenuation
(TW,Ast)
'equiripple'
–– Equiripple method supports all the design specification combinations.'ls'
–– Least squares method supports the filter order (N) and transition width (TW) specifications.
For more information on the filter design methods, see Algorithms.
Data Types: char
| string
Passband
— Passband frequency response
'lowpass'
(default) | 'highpass'
Passband frequency response, specified as one of these:
'lowpass'
–– This option supports all three filter structures when you setSystemObject
totrue
.'highpass'
–– This option supports only the'single-rate'
filter structure when you setSystemObject
totrue
.
Data Types: char
| string
SystemObject
— Option to create System object
false
(default) |
true
Option to create System object, specified as one of these:
false
–– The function returns a vector of halfband FIR filter coefficients.true
–– The function returns a:dsp.FIRFilter
object when you setStructure
to'single-rate'
.dsp.FIRHalfbandInterpolator
object when you setStructure
to'interp'
.dsp.FIRHalfbandDecimator
object when you setStructure
to'decim'
.
Data Types: logical
Structure
— Filter structure
'single-rate'
(default) | 'decim'
| 'interp'
Filter structure, specified as one of these:
'single-rate'
–– When you setSystemObject
to:true
–– The function returns adsp.FIRFilter
object.false
–– The function returns a vector of halfband FIR filter coefficients. The center coefficient is 0.5.
'decim'
–– When you setSystemObject
to:true
–– The function returns adsp.FIRHalfbandDecimator
object.false
–– The function returns a vector of halfband FIR filter coefficients. The center coefficient is 0.5.
'interp'
–– When you setSystemObject
to:true
–– The function returns adsp.FIRHalfbandInterpolator
object.false
–– The function returns a vector of halfband FIR filter coefficients. The filter coefficients are scaled by 2 and the center coefficient is 1.0.
Data Types: char
| string
Verbose
— Option to print function call in MATLAB®
false
(default) | true
Option to print the entire function call in MATLAB, specified as one of these:
false
–– The function does not print the function call.true
–– The function prints the entire function call including the default values of theName=Value
arguments that you did not specify when calling the function.Use this argument to view all the values used by the function to design and implement the filter.
Data Types: logical
Output Arguments
B
— Filter coefficients or filter object
row vector | dsp.FIRFilter
object | dsp.FIRHalfbandDecimator
object | dsp.FIRHalfbandInterpolator
object
dsp.FIRFilter
dsp.FIRHalfbandDecimator
dsp.FIRHalfbandInterpolator
Halfband FIR filter coefficients or filter object, returned as one of these:
Row vector –– The function returns a row vector of length
FilterOrder
+ 1 when you set theSystemObject
argument tofalse
.dsp.FIRFilter
System object –– The function returns adsp.FIRFilter
object when you setStructure
to'single-rate'
and theSystemObject
argument totrue
.dsp.FIRHalfbandDecimator
System object –– The function returns adsp.FIRHalfbandDecimator
object when you setStructure
to'decim'
and theSystemObject
argument totrue
.dsp.FIRHalfbandInterpolator
System object –– The function returns adsp.FIRHalfbandInterpolator
object when you setStructure
to'interp'
and theSystemObject
argument totrue
.
Data Types: single
| double
More About
Halfband Filters
An ideal lowpass halfband filter is given by
An ideal filter is not realizable. However, the impulse response of an ideal lowpass filter possesses some important properties that are required in a realizable approximation. The impulse response of an ideal lowpass halfband filter is:
Equal to 0 for all even-indexed samples.
Equal to 1/2 at n=0 as shown by L'Hôpital's rule on the continuous-valued equivalent of the discrete-time impulse response
The ideal highpass halfband filter is given by
Evaluating this integral yields the impulse response
The impulse response of an ideal highpass halfband filter is:
Equal to 0 for all even-indexed samples
Equal to 1/2 at n=0
The FIR halfband filter uses a causal FIR approximation of the ideal halfband response. The approximation is based on minimizing the norm of the error (minimax). See Algorithms for more information.
Kaiser Window
The designHalfbandFIR
function computes the coefficients of a
Kaiser window using the equation
where I0 is the zeroth-order modified Bessel function of the first kind.
To obtain a Kaiser window that represents an FIR filter with stopband attenuation of α dB, use this β.
The filter order n is given by
where Δω is the transition width.
Algorithms
Filter Design Method
The designHalfbandFIR
function uses the equiripple, Kaiser, or
the least-squares linear phase window method to design the FIR halfband filter. When the
design constraints are tight, such as very high stopband attenuation or very narrow
transition width, use the Kaiser window method. If you are not sure of which method to
use, set the design method to "auto"
. In this mode, the algorithm
automatically chooses a design method that optimally meets the specified filter
constraints.
Halfband Equiripple Design
In the equiripple method, the algorithm uses a minimax (minimize the maximum error) FIR design to design a fullband linear phase filter with the desired specifications. The algorithm upsamples a fullband filter to replace the even-indexed samples of the filter with zeros and creates a halfband filter. It then sets the filter tap corresponding to the group delay of the filter in samples to 1/2. This yields a causal linear-phase FIR filter approximation to the ideal halfband filter defined in Halfband Filters. See [1] for a description of this filter design method using the Remez exchange algorithm. As you can design a filter using this approximation method with a constant ripple both in the passband and stopband, the filter is also known as the equiripple filter.
Halfband Kaiser Window Design
In the Kaiser window method, the algorithm first truncates the ideal halfband filter defined in Halfband Filters, then it applies a Kaiser window defined in Kaiser Window. This yields a causal linear-phase FIR filter approximation to the ideal halfband filter.
Least-Squares Linear-Phase FIR Filter Design
The function designs a linear-phase FIR filter by minimizing the weighted, integrated, and squared error between the magnitude response of the ideal halfband filter and the filter designed for the given set of specifications. For more information, see [3].
Filter Implementation
To implement the designed filter, set SystemObject
to
true
and Structure
to:
'single-rate'
–– The function generates adsp.FIRFilter
object.'interp'
–– The function generates adsp.FIRHalfbandInterpolator
object.'decim'
–– The function generates adsp.FIRHalfbandDecimator
object.
For more information on how the objects implement the filters, see the Algorithms section in the corresponding object reference page.
References
[1] Harris, F.J. Multirate Signal Processing for Communication Systems, Prentice Hall, 2004, pp. 208–209.
[2] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1996.
[3] Oppenheim, Alan V., Ronald W. Schafer, and John R. Buck. Discrete-Time Signal Processing. Upper Saddle River, NJ: Prentice Hall, 1999.
[4] Parks, Thomas W., and C. Sidney Burrus. Digital Filter Design. Hoboken, NJ: John Wiley & Sons, 1987, pp. 54–83.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
The designHalfbandFIR
function generates code under these conditions:
If you set
SystemObject
totrue
, then all the filter design specifications must be constant while generating code.B = designHalfbandFIR(TransitionWidth=tw,FilterOrder=n,DesignMethod='kaiser',SystemObject=true)
% Code generation failsB = designHalfbandFIR(TransitionWidth=0.1,StopbandAttenuation=80,DesignMethod='kaiser',SystemObject=true)
% Code generation worksIf you set
DesignMethod
to"auto"
or"equiripple"
, then all the filter design specifications must be constant while generating code.B = designHalfbandFIR(TransitionWidth=tw,StopbandAttenuation=ast,DesignMethod='equiripple')
% Code generation failsB = designHalfbandFIR(TransitionWidth=0.1,StopbandAttenuation=80,DesignMethod='equiripple')
% Code generation worksIf you set
DesignMethod
to"kaiser"
and specifyStopbandAttenuation
, then all the filter design specifications must be constant while generating code.B = designHalfbandFIR(TransitionWidth=tw,StopbandAttenuation=ast,DesignMethod='kaiser')
% Code generation failsB = designHalfbandFIR(TransitionWidth=0.1,StopbandAttenuation=80,DesignMethod='kaiser')
% Code generation worksIf you set
DesignMethod
to"kaiser"
, specify theFilterOrder
andTransitionWidth
specifications, and setSystemObject
tofalse
, then the function supports code generation with no limitations.B = designHalfbandFIR(TransitionWidth=tw,FilterOrder=n,DesignMethod='kaiser')
% Code generation worksIf you set
DesignMethod
to"ls"
and setSystemObject
tofalse
, then the function supports code generation with no limitations.
tw
and ast
are runtime variables whose values
are not determined during code generation.
Version History
Introduced in R2023b
See Also
Functions
designHalfbandIIR
|designLowpassFIR
|designHighpassFIR
|designMultirateFIR
|designFracDelayFIR
|outputDelay
Objects
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)