designHighpassFIR
Description
designs a highpass
FIR filter with the filter order of 100, cutoff frequency of 0.25, and a Hamming window.
B
= designHighpassFIRB
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
= designHighpassFIR(Name=Value
)
For example,
designs a highpass FIR filter with the filter order of 30, cutoff frequency of 0.5, and
a Hann window. As the B
=
designHighpassFIR
(FilterOrder
=30,CutoffFrequency
=0.5,Window
="hann",SystemObject
=true)SystemObject
argument is
true
, the function designs and implements the highpass 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 Highpass FIR Filter with Tunable Cutoff Frequency
Create a dsp.FIRFilter
object, and set the NumeratorSource
property to 'Input port'
so that you can vary the coefficients of the FIR filter through the input port 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 designHighpassFIR
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 cutoff frequency of the filter during simulation. The designHighpassFIR
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.
Fcut = 0.5; for idx = 1:500 num = designHighpassFIR(FilterOrder=30,CutoffFrequency=Fcut,Window="hann"); x = randn(1024,1); y = firFilt(x,num); spectrumScope(x,y); filterViz(num); Fcut = Fcut + 0.0001; end
Design and Implement Highpass FIR Filter Object
Design and implement a highpass FIR filter object using the designHighpassFIR
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 = designHighpassFIR(FilterOrder=30,CutoffFrequency=0.5,... Window="hann",Datatype="single",SystemObject=true)
firFilt = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [0 -2.1297e-19 -0.0011 1.8613e-18 0.0048 -4.8729e-18 -0.0122 8.7270e-18 0.0251 -1.2757e-17 -0.0477 1.6267e-17 0.0960 -1.8649e-17 -0.3148 0.5000 -0.3148 -1.8649e-17 0.0960 1.6267e-17 -0.0477 -1.2757e-17 0.0251 ... ] (1x31 single) InitialConditions: 0 Use get to show all properties
Create a dsp.DynamicFilterVisualizer
object to visualize the magnitude response of the 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:
designHighpassFIR(FilterOrder=30,CutoffFrequency=0.3)
FilterOrder
— Order of highpass FIR filter
100
(default) | even nonnegative integer
Order of the highpass FIR filter, N, specified as an even nonnegative integer.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
CutoffFrequency
— Cutoff frequency of highpass FIR filter
0.25
(default) | scalar in the range (0
,1
]
Cutoff frequency of the highpass FIR filter, Fcut,
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 =
designHighpassFIR(FilterOrder=N,CutoffFrequency=Fcut,like=single(N))
Example: N = single(110); B =
designHighpassFIR(FilterOrder=N,CutoffFrequency=Fcut,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 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.FIRFilter
Highpass 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
designHighpassIIR
|designLowpassFIR
|designBandpassFIR
|designBandstopFIR
|designHalfbandFIR
|designMultirateFIR
|designFracDelayFIR
|designRateConverter
Objects
Blocks
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes 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)