Upsample, filter, and downsample input signals
DSP System Toolbox / Filtering / Multirate Filters
The FIR Rate Conversion block resamples the discrete-time input such that its sample period is K/L times the input sample period (Tsi). K is the integer value you specify for the Decimation factor parameter, and L is the integer value you specify for the Interpolation factor parameter.
The block treats each column of the input as a separate channel and resamples the data in each channel independently over time. To do so, the block implements a polyphase filter structure and performs the following operations:
Upsamples the input to a higher rate by inserting
L−1
zeros between input
samples.
Passes the upsampled data through a direct-form II transpose FIR filter.
Downsamples the filtered data to a lower rate by discarding
K-1
consecutive samples following each
sample that the block retains.
The polyphase filter implementation is more efficient than a straightforward upsample-filter-decimate algorithm. See Orfanidis [1] for more information.
Port_1(In1)
— Input signalInput signal, specified as a vector or a matrix.
When the block input is fixed point, all internal data types are signed fixed point.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
Complex Number Support: Yes
Port_1(Out1)
— Rate converted signalRate converted signal, returned as a vector or a matrix.
When the Rate options parameter is set to:
Enforce single-rate processing
–– The output frame size
Mo is
L/K times the
input frame size
Mi, where
L is the interpolation factor and
K is the decimation factor.
Mo = (L/K)×Mi
The output signal rate in Simulink® equals the input signal rate.
Fo = Fi
Allow multirate processing
––
The output frame size equals the input frame size.
Mo = Mi
The output signal rate in Simulink is L/K times the input signal rate.
Fo = (L/K)×Fi
All blocks connected to the output operate at Fo, and all blocks connected to the input operate at Fi.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fixed point
Complex Number Support: Yes
Coefficient source
— Mode of operationThe FIR Rate Conversion block can operate in three different modes. Select the mode in the Coefficient source group box.
Dialog parameters — Enter information about the filter, such as FIR filter coefficients in the block dialog box.
Filter object — Specify the filter
using a dsp.FIRRateConverter
System object™.
Auto (default) — The block determines the filter coefficients.
The settings in the FIR Rate Conversion block dialog box change based on the mode selected.
Interpolation factor
— Interpolation factor3
(default) | positive integerSpecify the interpolation factor, L, as a positive integer. The block upsamples the signal by this value before filtering it.
To enable this parameter, set Coefficient source to either Dialog parameters or Auto.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
FIR filter coefficients
— FIR filter coefficientsdesignMultirateFIR(3,2)
(default) | vectorSpecify the FIR filter coefficients in descending powers of z. By
default, the block uses the designMultirateFIR(3,2)
function to compute the filter coefficients.
To enable this parameter, set Coefficient source to Dialog parameters.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Complex Number Support: Yes
Decimation factor
— Decimation factor2
(default) | positive integerSpecify the decimation factor, K, as a positive integer. The block downsamples the signal by this value after filtering it.
To enable this parameter, set Coefficient source to either Dialog parameters or Auto.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Rate options
— Enforce single-rate or allow multirate processingEnforce single-rate
processing
(default) | Allow multirate processing
Specify whether to enforce single-rate processing or allow multirate processing.
Enforce single-rate processing
–– The output frame size
Mo is
L/K times the
input frame size
Mi, where
L is the interpolation factor and
K is the decimation factor.
Mo = (L/K)×Mi
The output signal rate in Simulink equals the input signal rate.
Fo = Fi
Allow multirate processing
––
The output frame size equals the input frame size.
Mo = Mi
The output signal rate in Simulink is L/K times the input signal rate.
Fo = (L/K)×Fi
All blocks connected to the output operate at Fo, and all blocks connected to the input operate at Fi.
Filter object
— Filter objectFRC
(default) | dsp.FIRRateConverter
System objectSpecify the multirate filter object that you want the block to implement. The specified
filter object must be a dsp.FIRRateConverter
System object.
You can define the System object in the block mask or in a MATLAB® workspace variable.
For information on creating System objects, see Define Basic System Objects.
This parameter appears when Coefficient source is set to Filter object.
View Filter Response
— Visualize filter responseSelect this parameter to open the Filter Visualization Tool, fvtool
, and display the magnitude response of the FIR
filter. The response is based on the parameters selected in the block
dialog box. Changes made to these parameters update
fvtool
.
To update the magnitude response while fvtool
is
running, modify the block parameters and click
Apply.
To view the magnitude response and phase response simultaneously, click the Magnitude and Phase responses button on the toolbar.
When Coefficient source is set to Filter object, the fixed-point settings of the filter object specified on the Main tab are displayed on the Data Types tab. You cannot change these settings directly on the block dialog box. To change the fixed-point settings, you must edit the filter object.
For more information on System objects, see the What Are System Objects?.
When Coefficient source is set to Auto, the block chooses the filter coefficients automatically. For more information on the filter design algorithm that the block uses, see Specify FIR Filter Coefficients.
Rounding mode
— Rounding methodFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Specify the rounding mode for fixed-point operations as:
Floor
Ceiling
Convergent
Nearest
Round
Simplest
Zero
For more details, see Rounding Modes.
The filter coefficients do not obey this parameter and always round to
Nearest
.
Note
The Rounding mode and Saturate on integer overflow parameters have no effect on numerical results when all these conditions are met:
Product output data type is
Inherit: Inherit via internal
rule
.
Accumulator data type is
Inherit: Inherit via internal
rule
.
Output data type is
Inherit: Same as
accumulator
.
With these data-type settings, the block operates in a full-precision mode.
To enable this parameter, set Coefficient source to either Dialog parameters or Auto.
Saturate on integer overflow
— Overflow handling methodSelect this parameter to saturate the result of the fixed-point operation. Clear this parameter to wrap the result of the fixed-point operation. For details on saturate and wrap, see Overflow Handling for fixed-point operations.
Note
The Rounding mode and Saturate on integer overflow parameters have no effect on numeric results when all these conditions are met:
Product output data type is
Inherit: Inherit via internal
rule
.
Accumulator data type is
Inherit: Inherit via internal
rule
.
With these data-type settings, the block operates in a full-precision mode.
This parameter is editable only when Coefficient source is set to either Dialog parameters or Auto.
Coefficients
— Coefficients data typeInherit: Same word length as
input
(default) | fixdt(1,16)
| fixdt(1,16,0)
Coefficients specifies the data type of the filter coefficients.
Inherit: Same word length as input
–– The block inherits the word length of the coefficients from
the fixed-point input. The fraction length is determined based
on the coefficient values in order to obtain the best possible
precision.
fixdt(1,16)
–– The coefficients
data type is a signed, binary-point, scaled, fixed-point data
type with a word length of 16 bits.
fixdt(1,16,0)
–– The coefficients
data type is a signed, binary-point, scaled, fixed-point data
type with a word length of 16 bits and a fraction length of
0.
Alternatively, you can set the Coefficients data
type by using the Data Type Assistant. To use the
assistant, click the Show data type assistant
button .
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
For a diagrammatic representation of how this block uses the filter coefficients data type, see Fixed Point.
This parameter is editable only when Coefficient source is set to either Dialog parameters or Auto.
Coefficients Minimum
— Minimum value of filter coefficients[]
(default) | scalarSpecify the minimum value of the filter coefficients. Simulink uses this minimum value to perform automatic scaling of fixed-point data types.
Coefficients Maximum
— Maximum value of filter coefficients[]
(default) | scalarSpecify the maximum value of the filter coefficients. Simulink uses this maximum value to perform automatic scaling of fixed-point data types.
Product output
— Product output data typeInherit: Inherit via internal
rule
(default) | Inherit: Same as input
| fixdt(1,16,0)
Product output specifies the data type of the output of a product operation in the FIR Rate Conversion block.
Inherit: Inherit via internal rule
— The block inherits the product output data type based
on an internal rule. For more information on this rule, see
Inherit via Internal Rule.
Inherit: Same as input
— The
block specifies the product output data type to be the same as
the input data type.
fixdt(1,16,0)
— The block
specifies a signed, binary-point, scaled, fixed-point data type
with a word length of 16 bits and a fraction length of 0.
Alternatively, you can set the Product output
data type by using the Data Type Assistant. To use
the assistant, click the Show data type assistant
button .
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
For a diagrammatic representation of how this block uses the product output data type, see Fixed Point.
This parameter is editable only when Coefficient source is set to either Dialog parameters or Auto.
Accumulator
— Accumulator data typeInherit: Inherit via internal
rule
(default) | Inherit: Same as input
| Inherit: Same as product output
| fixdt(1,16,0)
Accumulator specifies the data type of the output of an accumulation operation in the FIR Rate Conversion block. For illustrations on how this block uses the accumulator data type, see Fixed Point.
Inherit: Inherit via internal rule
— The block inherits the accumulator data type based on
an internal rule. For more information on this rule, see Inherit via Internal Rule.
Inherit: Same as input
— The
block specifies the accumulator data type to be the same as the
input data type.
Inherit: Same as product output
— The block specifies the accumulator data type to be the
same as the product output data type.
fixdt(1,16,0)
— The block
specifies a signed, binary-point, scaled, fixed-point data type
with a word length of 16 bits and a fraction length of 0.
Alternatively, you can set the Accumulator data
type by using the Data Type Assistant. To use the
assistant, click the Show data type assistant button.
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
This parameter is editable only when Coefficient source is set to either Dialog parameters or Auto.
Output
— Output data typeInherit: Same as
accumulator
(default) | Inherit: Same as input
| Inherit: Same as product output
| fixdt(1,16,0)
Output specifies the data type of the output of the FIR Rate Conversion block.
Inherit: Same as input
— The
block specifies the output data type to be the same as the input
data type.
Inherit: Same as product output
— The block specifies the output data type to be the same
as the product output data type.
Inherit: Same as accumulator
— The block specifies the output data type to be the same
as the accumulator data type.
fixdt(1,16,0)
— The block
specifies a signed, binary-point, scaled, fixed-point data type
with a word length of 16 bits and a fraction length of 0.
Alternatively, you can set the Output data type
by using the Data Type Assistant. To use the
assistant, click the Show data type assistant
button .
For more information on the data type assistant, see Specify Data Types Using Data Type Assistant (Simulink).
For a diagrammatic representation of how this block uses the output data type, see Fixed Point.
This parameter is editable only when Coefficient source is set to either Dialog parameters or Auto.
Output Minimum
— Minimum value the block can output[]
(default) | scalarSpecify the minimum value the block can output. Simulink uses this minimum value to perform:
Simulation range checking. For more information, see Specify Signal Ranges (Simulink).
Automatic scaling of fixed-point data types.
Output Maximum
— Maximum value block can output[]
(default) | scalarSpecify the maximum value the block can output. Simulink uses this maximum value to perform:
Simulation range checking. For more information, see Specify Signal Ranges (Simulink).
Automatic scaling of fixed-point data types.
Lock data type settings against changes by the fixed-point tools
— Prevent fixed-point tools from overriding data typesoff
(default) | on
Select this parameter to prevent the fixed-point tools from overriding the data types you specify on the block dialog box.
This parameter appears only when Coefficient source is set to either Dialog parameters or Auto.
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
When you select the Dialog parameters option, you use the FIR filter coefficients parameter to specify the numerator coefficients of the FIR filter transfer function H(z).
You can generate the FIR filter coefficient vector, [b(1) b(2) ...
b(m)]
, using one of the DSP System Toolbox™ filter design functions such as designMultirateFIR
, firnyquist
, firhalfband
, firgr
, or firceqrip
.
The coefficient vector you specify must have a length greater than the interpolation factor
(m>L). The FIR filter must be a lowpass
filter with a normalized cutoff frequency no greater than
min
(1
/L,1/K).
The block internally initializes all filter states to zero.
When you select the Auto mode, the block designs an FIR multirate
filter with the decimation factor specified in Decimation
factor and interpolation factor specified in Interpolation
factor. The designMultirateFIR
function designs the filter and returns the
coefficients used by the block. For more information on the filter design algorithm,
see Orfanidis [1].
This section applies only to the single-rate processing mode when the Rate
options parameter is set to Enforce single-rate
processing
.
You specify the resampling rate of the FIR Rate Conversion block using the Decimation factor and Interpolation factor parameters. For an Mi-by-N matrix input, the Decimation factor K and the Interpolation factor L must satisfy these requirements:
K and L must be relatively prime integers. That is, the ratio K/L cannot be reduced to a ratio of smaller integers.
, where Mi and Mo are the integer frame sizes of the input and output, respectively.
You can satisfy the second requirement by setting the Decimation factor, K, to equal the input frame size Mi. When you do so, the output frame size Mo equals the Interpolation factor L.
By changing the frame size in this way, the block is able to hold the frame period constant (Tfi = Tfo) and achieve the desired conversion of the sample period, such that
where Tso is the output sample period.
This figure shows how the FIR Rate Conversion block converts a
4
-by-1
input with a sample period of
3
/4
to a
3
-by-1
output with a sample period of
1
. The frame period
(Tf) of 3
remains constant.
[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1996.
Generated code relies on memcpy
or
memset
functions (string.h
) under certain
conditions.
This diagram shows the data types used within the FIR Rate Conversion block for fixed-point signals.
You can set the coefficient, product output, accumulator, and output data types in the block dialog box. The diagram shows that input data is stored in the input buffer in the same data type and scaling as the input. Filtered data resides in the output buffer in the output data type and scaling that you set in the block dialog. The block stores any initial conditions in the output buffer using the output data type and scaling that you set in the block dialog box.
The output of the multiplier is in the product output data type when at least one of the inputs to the multiplier is real. When both the inputs to the multiplier are complex, the result of the multiplication is in the accumulator data type. For details on how the complex multiplication is performed in the block, see Multiplication Data Types.
Note
When the block input is fixed point, all internal data types are signed fixed point.
firceqrip
| firgr
| firhalfband
| firnyquist
dsp.CICCompensationDecimator
| dsp.CICCompensationInterpolator
| dsp.FIRDecimator
| dsp.FIRHalfbandDecimator
| dsp.FIRHalfbandInterpolator
| dsp.FIRInterpolator