Static or time-varying FIR filter
The dsp.FIRFilter
System object™ filters each channel of the input using static or time-varying FIR filter
implementations.
To filter each channel of the input:
Create the dsp.FIRFilter
object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
Under specific conditions, this System object also supports SIMD code generation. For details, see Code Generation.
returns a finite impulse
response (FIR) filter object, fir
= dsp.FIRFilterfir
, which independently filters each
channel of the input over time using a specified FIR filter implementation.
returns an FIR filter System object, fir
= dsp.FIRFilter(num
)fir
, with the Numerator
property
set to num
.
returns an FIR filter System object, fir
= dsp.FIRFilter(Name,Value
)fir
, with each property set to the specified
value.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
Structure
— Filter structureDirect form
(default) | Direct form symmetric
| Direct form antisymmetric
| Direct form transposed
| Lattice MA
Specify the filter structure. You can specify the filter structure as one of
Direct form
| Direct form symmetric
|
Direct form antisymmetric
| Direct form
transposed
| Lattice MA
.
NumeratorSource
— Source of filter coefficientsProperty
(default) | Input port
Specify the source of the filter coefficients as Property
or
Input port
. When you specify Input port
, the
filter object updates the time-varying filter once every frame.
This applies when you set the Structure
to
Direct form
| Direct form symmetric
|
Direct form antisymmetric
| Direct form
transposed
.
ReflectionCoefficientsSource
— Source of filter coefficientsProperty
(default) | Input port
Specify the source of the Lattice filter coefficients as Property
or Input port
. When you specify Input port
, the
filter object updates the time-varying filter once every frame.
This applies when you set the Structure
to
Lattice MA
.
Numerator
— Numerator coefficients[0.5 0.5]
(default) | row vectorSpecify the filter coefficients as a real or complex numeric row vector.
Tunable: Yes
This property applies when you set the NumeratorSource
property to Property
, and the Structure property is set to Direct
form
, Direct form symmetric
, Direct form
antisymmetric
, or Direct form transposed
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Complex Number Support: Yes
ReflectionCoefficients
— Reflection coefficients of lattice filter structure[0.5 0.5]
(default) | row vectorSpecify the reflection coefficients of a lattice filter as a real or complex numeric row vector.
Tunable: Yes
This property applies when you set the Structure property to Lattice
MA
, and the ReflectionCoefficientsSource
property to
Property
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Complex Number Support: Yes
InitialConditions
— Initial conditions for the FIR filter0
(default) | scalar | vector | matrixSpecify the initial conditions of the filter states. The number of states or delay elements equals the number of reflection coefficients for the lattice structure, or the number of filter coefficients–1 for the other direct form structures.
You can specify the initial conditions as a scalar, vector, or matrix. If you specify a scalar value, the FIR filter object initializes all delay elements in the filter to that value. If you specify a vector whose length equals the number of delay elements in the filter, each vector element specifies a unique initial condition for the corresponding delay element. The object applies the same vector of initial conditions to each channel of the input signal.
If you specify a vector whose length equals the product of the number of input channels and the number of delay elements in the filter, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel.
If you specify a matrix with the same number of rows as the number of delay elements in the filter, and one column for each channel of the input signal, each element specifies a unique initial condition for the corresponding delay element in the corresponding channel.
Tunable: Yes
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
FullPrecisionOverride
— Full precision override for fixed-point arithmetictrue
(default) | false
Specify whether to use full precision rules. If you set FullPrecisionOverride
to true
, which is the default,
the object computes all internal arithmetic and output data types using full precision
rules. These rules provide the most accurate fixed-point numerics. It also turns off
the display of other fixed-point properties because they do not apply individually.
These rules guarantee that no quantization occurs within the object. Bits are added,
as needed, to ensure that no roundoff or overflow occurs. If you set FullPrecisionOverride
to false
,
fixed-point data types are controlled through individual fixed-point property
settings. For more information, see Full Precision for Fixed-Point System Objects.
RoundingMethod
— Rounding method for fixed-point operationsFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Specify the rounding method.
This property applies only if the object is not in full precision mode.
OverflowAction
— Overflow action for fixed-point operationsWrap
(default) | Saturate
Specify the overflow action as Wrap
or
Saturate
.
This property applies only if the object is not in full precision mode.
CoefficientsDataType
— Coefficients word and fraction lengthsSame word length as input
(default) | Custom
Specify the coefficients fixed-point data type as Same word length as
input
or Custom
.
This property applies when you set the NumeratorSource
property to Property
.
CustomCoefficientsDataType
— Custom coefficients word and fraction lengthsnumerictype(true,16,15)
(default) | numerictypeSpecify the coefficients fixed-point type as a signed or unsigned numerictype
(Fixed-Point Designer) object.
This property applies when you set the CoefficientsDataType
property to Custom
.
ReflectionCoefficientsDataType
— Reflection coefficients word and fraction lengthsSame word length as input
(default) | Custom
Specify the reflection coefficients fixed-point data type as Same word
length as input
or Custom
.
This property applies when you set the
ReflectionCoefficientsSource
property to
Property
.
CustomReflectionCoefficientsDataType
— Custom reflection coefficients word and fraction lengthsnumerictype(true,16,15)
(default) | numerictypeSpecify the reflection coefficients fixed-point type as a signed or unsigned
numerictype
(Fixed-Point Designer) object.
This property applies when you set the
ReflectionCoefficientsDataType
property to
Custom
.
ProductDataType
— Product word and fraction lengthsFull precision
(default) | Same as input
| Custom
Specify the product fixed-point data type as Full precision
,
Same as input
, or Custom
.
CustomProductDataType
— Custom product word and fraction lengthsnumerictype(true,32,30)
(default) | numerictypeSpecify the product fixed-point type as a signed or unsigned scaled numerictype
(Fixed-Point Designer) object.
This property applies when you set the ProductDataType
property to Custom
.
AccumulatorDataType
— Accumulator word and fraction lengthsFull precision
(default) | Same as input
| Same as product
| Custom
Specify the accumulator fixed-point data type to Full
precision
, Same as input
, Same as
product
, or Custom
.
CustomAccumulatorDataType
— Custom accumulator word and fraction lengthsnumerictype(true,32,30)
(default) | numerictypeSpecify the accumulator fixed-point type as a signed or unsigned scaled numerictype
(Fixed-Point Designer) object.
This property applies when you set the AccumulatorDataType
property to Custom
.
StateDataType
— State word and fraction lengthsSame as accumulator
(default) | Same as input
| Custom
Specify the state fixed-point data type as one of Same as
input
, Same as accumulator
, or
Custom
.
This property does not apply to any of the direct form or direct form I filter structures.
CustomStateDataType
— Custom state word and fraction lengthsnumerictype(true,16,15)
(default) | numerictypeSpecify the state fixed-point type as a signed or unsigned scaled numerictype
(Fixed-Point Designer) object.
This property applies when you set the StateDataType
property to Custom
.
OutputDataType
— Output word and fraction lengthsSame as accumulator
(default) | Same as input
| Custom
Specify the output fixed-point data type as one of Same as
input
, Same as accumulator
, or
Custom
.
CustomOutputDataType
— Custom output word and fraction lengthsSpecify the output fixed-point type as a signed or unsigned scaled numerictype
(Fixed-Point Designer) object.
This property applies when you set the OutputDataType property to
Custom
.
x
— Data inputData input, specified as a vector or a matrix. When the input data is of a
fixed-point type, it must be signed when the structure is set to Direct form
symmetric
or Direct form antisymmetric
. The FIR filter
object operates on each channel of the input signal independently over successive
calls to the object.
This System object supports variable-size input.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
coeff
— Filter coefficientsTime-varying filter coefficients, specified as a row vector. The data and coefficient inputs must have the same data type.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
y
— Filtered outputFiltered output, returned as a vector or a matrix. The output has the same size and data type as the input.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
| fi
Complex Number Support: Yes
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
dsp.FIRFilter
freqz | Frequency response of discrete-time filter System object |
fvtool | Visualize frequency response of DSP filters |
impz | Impulse response of discrete-time filter System object |
info | Information about filter System object |
coeffs | Returns the filter System object coefficients in a structure |
cost | Estimate cost of implementing filter System object |
grpdelay | Group delay response of discrete-time filter System object |
generatehdl | Generate HDL code for quantized DSP filter (requires Filter Design HDL Coder) |
Use an FIR filter to apply a low pass filter to a waveform with two sinusoidal components.
t = (0:1000)'/8e3; xin = sin(2*pi*0.3e3*t)+sin(2*pi*3e3*t); sr = dsp.SignalSource; sr.Signal = xin; sink = dsp.SignalSink; fir = dsp.FIRFilter(fir1(10,0.5)); sa = dsp.SpectrumAnalyzer('SampleRate',8e3,... 'PlotAsTwoSidedSpectrum',false,... 'OverlapPercent', 80, 'PowerUnits','dBW',... 'YLimits', [-150 -10]); while ~isDone(sr) input = sr(); filteredOutput = fir(input); sink(filteredOutput); sa(filteredOutput) end filteredResult = sink.Buffer; fvtool(fir,'Fs',8000)
Design an FIR filter as a System object.
N = 10; Fc = 0.4; B = fir1(N,Fc); fir1 = dsp.FIRFilter(B); fvtool(fir1)
This can also be achieved by using fdesign
as a constructor and design
to design the filter.
N = 10; Fc = 0.4; specLowpass = fdesign.lowpass('N,Fc',N,Fc); fir2 = design(specLowpass,'systemobject',true) fvtool(fir2);
fir2 = dsp.FIRFilter with properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [1x11 double] InitialConditions: 0 Use get to show all properties
This object implements the algorithm, inputs, and outputs described on the Discrete FIR Filter (Simulink) block reference page. The object properties correspond to the block parameters.
Usage notes and limitations:
Only the Numerator
property is tunable for code
generation.
See System Objects in MATLAB Code Generation (MATLAB Coder).
The dsp.FIRFilter
System object supports SIMD code generation using Intel AVX2 technology under these
conditions:
Filter structure is set to 'Direct form'
or 'Direct
form transposed'
.
Input signal is real-valued with real filter coefficients.
When filter structure is set to 'Direct form'
, the input signal
can also be complex-valued with real or complex filter coefficients.
Input signal has a data type of single
or
double
.
The SIMD technology significantly improves the performance of the generated code.
You have a modified version of this example. Do you want to open this example with your edits?