designBandstopFIR
Description
designs a bandstop
FIR filter with the filter order of 100, center frequency of 0.5, bandwidth of 0.1, and
a Hamming window. B
= designBandstopFIRB
is a vector of filter coefficients of length
101.
The System object™ argument is false
by default. To implement the filter,
assign the filter coefficients in B
to a dsp.FIRFilter
object.
specifies options using one or more name-value arguments.B
= designBandstopFIR(Name=Value
)
For example,
designs a bandstop FIR filter with the filter order of 30, center frequency of 0.4, and
a Hann window. As the B
=
designBandstopFIR
(FilterOrder
=30,CenterFrequency
=0.4,Window
="hann",SystemObject
=true)SystemObject
argument is
true
, the function designs and implements the bandstop 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.
When you specify any of the numeric input arguments in single precision, the function
designs the filter coefficients in single precision. Alternatively, you can use the Datatype
and
like
arguments to control the coefficients data
type. (since R2024b)
Examples
Design and Implement Bandstop FIR Filter with Tunable Center Frequency
Create a dsp.FIRFilter
object, and set the NumeratorSource
property to 'Input port'
so that you can vary the FIR filter coefficients through the input during simulation.
firFilt = dsp.FIRFilter(NumeratorSource="Input port")
firFilt = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Input port' InitialConditions: 0 Use get to show all properties
Create a spectrumAnalyzer
object to visualize the spectra of the input and output signals.
spectrumScope = spectrumAnalyzer(SampleRate=44100,PlotAsTwoSidedSpectrum=false,... ChannelNames=["Input Signal","Filtered Signal"]);
Create a dsp.DynamicFilterVisualizer
object to visualize the magnitude response of the varying filter.
filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true);
Stream in random data and filter the signal using the dsp.FIRFilter
object. Use the designBandstopFIR
function to design the filter coefficients. By default, this function returns a vector of FIR filter coefficients. Assign these coefficients to the dsp.FIRFilter
object.
Vary the center frequency of the filter during simulation. The designBandstopFIR
function redesigns the coefficients based on the updated filter specifications. Pass these updated coefficients to the FIR filter. Visualize the spectra of the input and filtered signals using the spectrum analyzer.
Fc = 0.5; for idx = 1:500 num = designBandstopFIR(FilterOrder=30,CenterFrequency=Fc,Bandwidth=0.2,Window="hann"); x = randn(1024,1); y = firFilt(x,num); spectrumScope(x,y); filterViz(num); Fc = Fc + 0.0001; end
Design and Implement Bandstop FIR Filter Object
Design and implement a bandstop FIR filter object using the designBandstopFIR
function. The function returns a dsp.FIRFilter
object when you set the SystemObject
argument to true
. To design the filter in single-precision, use the Datatype
or like
argument. Alternatively, you can specify any of the numerical arguments in single-precision.
firFilt = designBandstopFIR(FilterOrder=30,CenterFrequency=0.5,Bandwidth=0.3,Window="hann",... Datatype="single",SystemObject=true)
firFilt = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [0 1.5217e-04 -3.2176e-19 0.0030 -2.0714e-17 -0.0158 1.1893e-17 0.0208 -3.3379e-18 0.0213 -2.0490e-17 -0.1252 3.4516e-17 0.2442 -1.7349e-17 0.7027 -1.7349e-17 0.2442 3.4516e-17 -0.1252 -2.0490e-17 0.0213 ... ] (1x31 single) InitialConditions: 0 Use get to show all properties
Create a dsp.DynamicFilterVisualizer
object to visualize the magnitude response of the varying filter.
filterViz = dsp.DynamicFilterVisualizer(NormalizedFrequency=true); filterViz(firFilt)
Create a spectrumAnalyzer
object to visualize the spectra of the input and output signals.
spectrumScope = spectrumAnalyzer(SampleRate=44100,PlotAsTwoSidedSpectrum=false,... ChannelNames=["Input Signal","Filtered Signal"]);
Stream in random data and filter the signal using the dsp.FIRFilter
object. Visualize the spectra of the input and filtered signals using the spectrum analyzer.
for idx = 1:500 x = randn(1024,1); y = firFilt(x); spectrumScope(x,y); end
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:
designBandstopFIR(FilterOrder=30,CenterFrequency=0.3,Bandwidth=0.2)
FilterOrder
— Order of bandstop FIR filter
100
(default) | even nonnegative integer
Order of the bandstop FIR filter, N, specified as an even nonnegative integer.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
CenterFrequency
— Center frequency of bandstop FIR filter
0.5
(default) | scalar in the range (0
,1
]
Center frequency of the bandstop FIR filter, Fc,
specified as a normalized scalar in the range
(0
,1
].
Data Types: single
| double
Bandwidth
— Bandwidth of bandstop FIR filter
0.1
(default) | scalar in the range (0
,1
]
Bandwidth of the bandstop FIR filter, BW, specified as a
normalized scalar in the range
(0
,1
].
Data Types: single
| double
Window
— Window design method
"hamming"
(default) |
"hann"
| "blackman"
|
"blackman-harris"
|
"chebyshev"
|
"kaiser"
|
"custom"
Window design method, specified as one of these options:
"hamming"
"hann"
"blackman"
"blackman-harris"
"chebyshev"
–– The default sidelobe attenuation is 60 dB."kaiser"
"custom"
–– Specify the custom window vector in theCustomWindow
argument.
Data Types: char
| string
CustomWindow
— Custom window vector
vector
Custom window vector, specified as a vector of length
FilterOrder
+ 1.
Data Types: single
| double
Datatype
— Data type of filter coefficients by type name
"double"
(default) | "single"
Since R2024b
Data type of the filter coefficients, specified by type name as
"double"
or
"single"
.
You can use the Dataype
or the
like
argument to specify the
data type of the filter coefficients, but you cannot use both
arguments at the same time.
If you specify the data type of the filter coefficients using this argument, the function ignores the data types of the other numeric arguments.
Data Types: char
| string
like
— Data type of filter coefficients by prototype
real floating-point value
Since R2024b
Data type of the filter coefficients, specified as a prototype of a real floating-point value.
You can use the Dataype
or the
like
argument to specify the data type of filter
coefficients, but you cannot use both arguments at the same time.
If you specify the data type of the filter coefficients using this argument, the function ignores the data types of the other numeric arguments.
Example: B =
designBandstopFIR(FilterOrder=N,CenterFrequency=Fc,like=single(N))
Example: N = single(110); B =
designBandstopFIR(FilterOrder=N,CenterFrequency=Fc,like=N)
Data Types: single
| double
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 FIR filter coefficients.true
–– The function returns adsp.FIRFilter
object.
Data Types: logical
Verbose
— Option to print function call in MATLAB®
false
(default) | true
Option to print 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.FIRFilter
Bandstop 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
.If you specify single-precision values in any of the input arguments, the function designs single-precision filter coefficients. (since R2024a)
If you specify the data type using the
Datatype
or thelike
argument, the function ignores the data types of the other numeric arguments. (since R2024b)dsp.FIRFilter
System object –– The function returns a filter object when you set theSystemObject
argument totrue
.
Data Types: single
| double
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
When you set the SystemObject
argument to
false
, the function supports code generation with no
limitations.
When you set the SystemObject
argument to
true
, the inputs to the function must be constants when generating
code.
This function supports strict single precision
in generated code. If any of the input arguments are in single precision, or you use the Datatype
and
like
arguments to specify single-precision (since R2024b), the code
you generate uses strictly single-precision arithmetic. (since R2024a)
Version History
Introduced in R2023bR2024b: Specify data type of filter coefficients explicitly
You can now specify the data type of filter coefficients explicitly using the
Datatype
and like
arguments.
R2024a: Support for strict single precision
When you specify single-precision values in any of the input arguments, the function designs single-precision filter coefficients both in simulation and in generated code.
See Also
Functions
designBandstopIIR
|designBandpassFIR
|designLowpassFIR
|designHighpassFIR
|designMultirateFIR
|designFracDelayFIR
Objects
Blocks
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.
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)