dsphdl.FIRInterpolator - Finite impulse response (FIR) interpolation filter - MATLAB (original) (raw)
Finite impulse response (FIR) interpolation filter
Since R2022a
Description
The dsphdl.FIRInterpolator
System object™ implements a single-rate polyphase FIR interpolation filter that is optimized for HDL code generation. The object provides a hardware-friendly interface with input and output control signals. To provide a cycle-accurate simulation of the generated HDL code, the object models architectural latency including pipeline registers and resource sharing.
The object accepts scalar or vector input and outputs a scalar or vector depending on the interpolation factor and the number of cycles between input samples. The object implements a polyphase decomposition with InterpolationFactor subfilters. The filter can implement a serial architecture if there is regular spacing between input samples.
The object provides two filter structures. The direct form systolic architecture provides a fully parallel implementation that makes efficient use of Intel® and Xilinx® DSP blocks. The direct form transposed architecture is a fully parallel implementation that is suitable for FPGA and ASIC applications. For a filter implementation that matches multipliers, pipeline registers, and pre-adders to the DSP configuration of your FPGA vendor, specify your target device when you generate HDL code.
All filter structures optimize hardware resources by sharing multipliers for symmetric or antisymmetric filters and by removing the multipliers for zero-valued coefficients such as in half-band filters and Hilbert transforms.
To filter and interpolate input data with an HDL-optimized algorithm::
- Create the
dsphdl.FIRInterpolator
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?
Note
You can also generate HDL code for this hardware-optimized algorithm, without creating a MATLAB® script, by using the DSP HDL IP Designer app. The app provides the same interface and configuration options as the System object.
Creation
Syntax
Description
`firInterp` = dsphdl.FIRInterpolator
returns a System objectfirInterp
, which upsamples and filters the input signal with the default settings.
firInterp = dsphdl.FIRInterpolator(INTERP,NUM)
returns a System objectfirInterp
with the InterpolationFactor
property set to INTERP
and the Numerator
property set toNUM
.
`firInterp` = dsphdl.FIRInterpolator(___,`Name=Value`)
returns an HDL FIR Interpolation System object with one or more properties set by name-value arguments.
Properties
Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and therelease function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, seeSystem Design in MATLAB Using System Objects.
Main
Since R2025a
You can enter constant filter coefficients as a property or provide time-varying filter coefficients using an input argument.
You cannot use programmable coefficients with multichannel data.
When you select 'Input port (Parallel interface)'
, the object has the coeff
argument.
Setting this property to 'Input port (Parallel interface)'
enables theNumeratorPrototype
property. Specify a prototype to enable the object to optimize the filter implementation according to the values of the coefficients.
When you use programmable coefficients with frame-based input, the output after a change of coefficient values might not match the output in the scalar case exactly. This difference occurs because the subfilter calculations are performed at different times relative to the input coefficient values, compared with the scalar implementation.
FIR filter coefficients, specified as a real- or complex-valued vector. You can specify the vector as a workspace variable or as a call to a filter design function. When the input data type is a floating-point type, the object casts the coefficients to the same data type as the input. When the input data type is an integer type or a fixed-point type, set the coefficient data type by using theCoefficientsDataType
property.
Example: firpm(30,[0 0.1 0.2 0.5]*2,[1 1 0 0])
defines coefficients by using a linear-phase filter design function.
Dependencies
To enable this property, set NumeratorSource
to'Input port (Parallel interface)'
.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Since R2025a
Prototype filter coefficients, specified as a vector of real or complex values. The prototype specifies a sample coefficient vector that is representative of the zero-value locations of the expected input coefficients. If all input coefficient vectors have the same zero-value coefficient locations, set NumeratorPrototype
to one of those vectors. The object uses the prototype to optimize the filter by removing multipliers for zero-value coefficients.
Dependencies
To enable this property, set NumeratorSource
to'Input port (Parallel interface)'
.
HDL filter architecture, specified as one of these structures:
'Direct form systolic'
— This architecture provides a fully parallel filter implementation that makes efficient use of Intel and Xilinx DSP blocks. For a partly serial implementation, specify a value greater than 1 for theNumCycles
property. You cannot use frame-based input with the partly serial architecture.'Direct form transposed'
— This architecture is a fully parallel implementation that is suitable for FPGA and ASIC applications.
The object implements a polyphase decomposition filter by using dsphdl.FIRFilter System objects. Each filter phase shares resources internally where coefficients and serial options allow. For architecture details, seeFIR Filter Architectures for FPGAs and ASICs. When you use a partly-serial systolic architecture and NumCycles
is larger than the filter length divided by the interpolation factor, the object interleaves each phase of coefficients over a single FIR filter to share resources between phases.
Interpolation factor, specified as integer greater than two. The output vector size is InputSize * InterpolationFactor. The output vector size must be less than 64 samples.
Specify the minimum number of cycles between the valid input samples as1
or a positive integer. This property represents_N_, the minimum number of cycles between valid input samples. When you set NumCycles
greater than the filter length,L, and the input and coefficients are both real, the filter uses a single multiplier.
Because the object applies coefficient optimizations before serialization, the sharing factor of the final filter can be lower than the number of cycles that you specified.
Dependencies
To enable this parameter, set FilterStructure
to'Direct form systolic'
.
You cannot use frame-based input with NumCycles
greater than 1.
Since R2024b
Enable sharing multipliers across symmetric coefficients in the polyphase filter architecture. This optimization reduces latency and halves the number of multipliers.
Polyphase decomposition of symmetric filter coefficients does not result in symmetry in each polyphase branch. For example, if the filter coefficients are[1 2 3 4 4 3 2 1]
, after decomposition the two polyphase branches are [1 3 4 2]
and [2 4 3 1]
. Symmetric pairs optimization refactors the coefficients to restore symmetry on the polyphase branches. The implementation includes a post-adder to combine output samples for the refactored polyphase branches. The filter output is the same as the output of the non-optimized implementation.
Data Types
Rounding method for type-casting the output, specified as'Floor'
, 'Ceiling'
,'Convergent'
, 'Nearest'
,'Round'
, or 'Zero'
. The object uses this property when casting the output to the data type specified by theOutputDataType
property. When the input data type is floating point, the object ignores this property. For more details, see Rounding Modes.
Overflow handling for type-casting the output, specified as'Wrap'
or 'Saturate'
. The object uses this property when casting the output to the data type specified by theOutputDataType
property. When the input data type is floating point, the object ignores this property. For more details, see Overflow Handling.
Data type of filter coefficients, specified as 'Same word length as input'
or a numerictype object. To specify anumerictype
object, callnumerictype(_s_,_w_,_f_)
, where:
- s is
1
for signed and0
for unsigned. - w is the word length in bits.
- f is the number of fractional bits.
When the input is a fixed-point or integer type, the object casts the filter coefficients using the rule or data type in this property. The quantization rounds to the nearest representable value and saturates on overflow. When the input data type is floating point, the object ignores this property and all internal arithmetic uses the same data type as the input.
The recommended data type for this parameter is 'Same word length as input'
.
Data type of the filter output, specified as 'Same word length as input'
, 'Full precision'
, or a numerictype object. To specify a numerictype
object, callnumerictype(_s_,_w_,_f_)
, where:
- s is
1
for signed and0
for unsigned. - w is the word length in bits.
- f is the number of fractional bits.
When the input is a fixed-point or integer type, the object casts the output of the filter using the rule or data type in this property. The quantization uses the settings of the RoundingMethod
andOverflowAction
properties. When the input data type is floating point, the object ignores this parameter and returns output in the same data type as the input.
The object increases the word length for full precision inside each filter tap and casts the final output to the specified type. The maximum final internal data type (WF) depends on the input data type (WI), the coefficient data type (WC), and the number of coefficients (L) and is given by
_WF_ = _WI_ + _WC_ + ceil(log2(_L_))
.
Because the coefficient values limit the potential growth, usually the actual full-precision internal word length is smaller than WF.
Control Arguments
Option to enable thereset
input argument, specified as true
orfalse
. When you set this property to true
, the object expects a value for the reset
input argument. The reset signal implements a local synchronous reset of the data path registers.
For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.
Option to connect the data path registers to the generated HDL global reset signal, specified as true
orfalse
. Set this property to true
to connect the generated HDL global reset signal to the data path registers. This property does not change the arguments of the object or modify simulation behavior in MATLAB. When you set this property to false
, the generated HDL global reset clears only the control path registers. The generated HDL global reset can be synchronous or asynchronous depending on your HDL code generation settings.
For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.
Usage
Syntax
Description
[[dataOut](#mw%5Fd3da4e11-bacb-4bcd-8a58-ec71f8d882b1),[validOut](#mw%5Fb278be75-e8ca-45a8-a8df-9c9044ca5eb5)] = firInterp([dataIn](#mw%5F367a3db5-d53c-4907-b765-22e415453dcb),[validIn](#mw%5F7d085100-66a2-4088-b38f-c341bcf823fe))
filters the input data only when validIn
istrue
.
[[dataOut](#mw%5Fd3da4e11-bacb-4bcd-8a58-ec71f8d882b1),[validOut](#mw%5Fb278be75-e8ca-45a8-a8df-9c9044ca5eb5)] = firInterp([dataIn](#mw%5F367a3db5-d53c-4907-b765-22e415453dcb),[validIn](#mw%5F7d085100-66a2-4088-b38f-c341bcf823fe),[coeff](#mw%5F055c8c8b-eb8e-4ea6-bf26-c2f26f5e6457))
filters data using the coefficients coeff
. Use this syntax when you set the NumeratorSource
property to 'Input port (Parallel interface)'
. For example:
firInterp = dsphdl.FIRDecimator(NumeratorSource='Input Port (Parallel interface)') Numerator = myGetNumerator(); % calculate coefficients for k=1:length(dataIn) [dataOut(x),validOut(x++)] = firInterp(dataIn(k),validIn(k),Numerator);
[[dataOut](#mw%5Fd3da4e11-bacb-4bcd-8a58-ec71f8d882b1),[validOut](#mw%5Fb278be75-e8ca-45a8-a8df-9c9044ca5eb5)] = firInterp([dataIn](#mw%5F367a3db5-d53c-4907-b765-22e415453dcb),[validIn](#mw%5F7d085100-66a2-4088-b38f-c341bcf823fe),[reset](#mw%5F1f51cf18-66f2-40e8-8705-80aa4022a9df))
filters data when reset
is false
. Whenreset
is true
, the object resets the filter registers. The object expects the reset
argument only when you set the ResetInputPort
property to true
.
For more reset considerations, see the Reset Signal section on the Hardware Control Signals page.
Input Arguments
Input data, specified as a real- or complex-valued scalar or vector. The vector size must be less than or equal to 64. When the input data type is an integer type or fixed-point type, the object uses fixed-point arithmetic for internal calculations.
The software supports double
andsingle
data types for simulation, but not for HDL code generation.
Data Types: fi
| single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Complex Number Support: Yes
Control signal that indicates if the input data is valid. WhenvalidIn
is 1
(true
), the object captures the values from the dataIn
argument. WhenvalidIn
is 0
(false
), the object ignores the values from the dataIn
argument.
Data Types: logical
Since R2025a
Filter coefficients, specified as a vector of real or complex values. You can change the input coefficients at any time. The size of the coefficient vector must match the size of the sample coefficients specified in theNumeratorPrototype
property. The prototype specifies a sample coefficient vector that is representative of the zero-value locations of the expected input coefficients. The object uses the prototype to optimize the filter by removing multipliers for zero-value coefficients.
If the input data
is a fixed-point type, thecoeff
values must also be of a fixed point type. If the inputdata
is a floating-point data type, thecoeff
values must be of the same data type.
The software supports double
andsingle
data types for simulation, but not for HDL code generation.
Dependencies
To enable this argument, set the NumeratorSource
property to 'Input port (Parallel interface)'
.
Data Types: fi
| single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Control signal that clears internal states. When reset
is1
(true
), the object stops the current calculation and clears internal states. When the reset
is0
(false
) and the inputvalid
is 1
(true
), the block captures data for processing.
For more reset considerations, see the Reset Signal section on theHardware Control Signals page.
Dependencies
To enable this argument, set the ResetInputPort
property totrue
.
Data Types: logical
Output Arguments
Interpolated output data, returned as a real or complex scalar or vector. The vector size is InputSize * InterpolationFactor. When NumCycles
is greater thanInterpolationFactor
, scalar output samples are spaced out withfloor(`NumCycles`/`InterpolationFactor`)
invalid cycles, and the output valid
signal indicates which samples are valid after interpolation.
When the input data is floating point, the output data inherits the data type of the input data. When the input data is an integer type or fixed-point type, theOutputDataType property specifies the output data type.
Data Types: fi
| single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Complex Number Support: Yes
Control signal that indicates if the output data is valid. WhenvalidOut
is 1
(true
), the object returns valid data from the dataOut
argument. WhenvalidOut
is 0
(false
), values from the dataOut
argument are not valid.
Data Types: logical
Control signal that indicates that the object is ready for new input data sample on the next cycle. When ready
is 1
(true
), you can specify the data
and valid
inputs for the next time step. Whenready
is 0
(false
), the object ignores any input data in the next time step.
Data Types: logical
Object Functions
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:
step | Run System object algorithm |
---|---|
release | Release resources and allow changes to System object property values and input characteristics |
reset | Reset internal states of System object |
Algorithms
This System object implements the algorithms described on the FIR Interpolator block reference page.
Extended Capabilities
This System object supports C/C++ code generation for accelerating MATLAB simulations, and for DPI component generation.
The software supports double
andsingle
data types for simulation, but not for HDL code generation.
To generate HDL code from predefined System objects, see Generate HDL Code for IIR Filter.
Version History
Introduced in R2022a
The object provides an optional coeff
port to allow coefficient changes at any time. Set the NumeratorSource
property to'Input port (Parallel interface)'
, and specify the filter coefficients as a row vector of real or complex values.
You can set the NumeratorPrototype
property to indicate the locations of consistently zero-valued coefficients, such as, if all input coefficients are half-band filters. When given a prototype, the object removes multipliers for zero-valued coefficients.
Set the OptimizeSymmCoeff
property to true
to enable optimizing symmetric coefficient multipliers in the polyphase filter architecture. This optimization reduces latency and halves the number of multipliers.
Starting in R2022b, when NumCycles
is greater than the filter length, the object interleaves the coefficients to share multipliers between the polyphase branches. To implement the filter with the minimum number of multipliers, set theNumCycles
property to Inf
.
In R2022a, the minimum number of multipliers that a partly serial FIR interpolator could use was InterpolationFactor multipliers, which occurred whenNumCycles
was equal to the filter length. IncreasingNumCycles
above the filter length resulted in no additional resource sharing.