Variable FIR Interpolation
Libraries:
DSP System Toolbox /
Filtering /
Multirate Filters
Description
The Variable FIR Interpolation block performs an efficient polyphase FIR interpolation with a tunable interpolation factor. You can update the interpolation factor and the filter coefficients in the block dialog box or through an input port while the simulation is running.
Conceptually, the FIR interpolator (as shown in the schematic) consists of an upsampler
followed by an FIR anti-imaging filter, which is usually an approximation of an ideal
band-limited interpolation filter. To design an FIR anti-imaging filter, use the designMultirateFIR
function. The upsampler upsamples each channel of the input
to a higher rate by inserting L–1 zeros between samples. The FIR filter
that follows filters each channel of the upsampled data. The resulting discrete-time signal
has a sample rate that is L times the original sample rate.
However, the actual block algorithm implements a direct-form FIR polyphase structure, an efficient equivalent of the combined system depicted in the diagram. For more details, see Algorithms.
The block supports C and C++ code generation.
Examples
Interpolate Variable-Size Sinusoidal Signal
Interpolate a sinusoidal signal whose frame size varies during simulation. The Variable FIR Interpolation block determines the frame size of the interpolated output based on the value of the Specification parameter.
Specify Interpolation Factor
Open and inspect the SpecifyInterpolationFactor.slx model. The Specification parameter in the Variable FIR Interpolation block dialog box is set to Interpolation factor
. In this mode, you specify the interpolation factor in the block dialog box or through an input port. During simulation, when the input frame size varies, the block maintains this interpolation factor and varies the output frame size so that output frame size equals input frame size x interpolation factor.
The Variable FIR Interpolation block outputs a variable-size signal.
Specify Output Frame Length
Open and inspect the SpecifyOutFrameLength.slx model. The Specification parameter in the Variable FIR Interpolation block dialog box is set to Output frame length
. In this mode, you specify the output frame length in the block dialog box. During simulation, when the input frame size varies, the block varies the interpolation factor in order to maintain the frame length of the output signal. The output frame size equals input frame size x interpolation factor.
The Variable FIR Interpolation block outputs a fixed-size signal.
Interpolate Sinusoidal Signal with Tunable Interpolation Factor
Interpolate a sinusoidal signal by varying the interpolation factor using the Variable FIR Interpolation block. You can vary the interpolation factor in the block dialog box or through an input port while the simulation is running.
Open the model. The input is a sinusoidal signal with a frequency of 500 Hz, sample time of 1/44100 s, and contains 100 samples per frame. Pass this signal through the Variable FIR Interpolation block. The Maximum interpolation factor parameter in the block is 24. The interpolation factor that you input through the port is 4.
Run the model. The Array Plot block shows the input signal and the interpolated output on the display.
While the simulation is running, change the interpolation factor to 2 by clicking the Manual Switch. The span of the interpolated output updates in the Array Plot display. You can change the interpolation factor to any value that is an integer factor of the maximum interpolation factor of 24.
If you specify the interpolation factor in the block dialog box, you can tune the Interpolation factor parameter in the block dialog box while the simulation is running and the block updates the interpolated output accordingly.
Specify Filter Coefficients Through Input Port
Interpolate a sinusoidal signal using the Variable FIR Interpolation block. You can vary the filter coefficients in the block dialog box or through an input port while the simulation is running.
Open the model. The input is a sinusoidal signal with a frequency of 500 Hz, sample time of 1/44100 s, and contains 100 samples per frame. Pass this signal through the Variable FIR Interpolation block. The Maximum interpolation factor parameter in the Variable FIR Interpolation block is set to 24. Specify the interpolation factor and the filter coefficients through the L and the coeffs ports, respectively. The interpolation factor is 4 and the filter coefficients are generated using the designMultirateFIR(24,1)
function. This function generates an effective anti-imaging lowpass filter with a normalized cutoff frequency no greater than 1/24.
You can vary the filter coefficients using the Manual Switch.
Run the model. The Array Plot block shows the input signal and the interpolated output in the display.
While the simulation is running, change the filter coefficients by clicking the Manual Switch. On the second branch, the fir1
function generates the coefficients of a lowpass filter that has a similar passband frequency response and the same number of coefficients as the first filter. Note that you cannot change the number of filter coefficients while the simulation is running.
Ports
Input
u — Data input
vector | matrix
Specify the data input as a vector or a matrix of size P-by-Q. The block treats each column of the input signal as a separate channel. If the input is a two-dimensional signal, the first dimension represents the channel length (or frame size) and the second dimension represents the number of channels. If the input is a one-dimensional signal, then the block interprets it as a single channel.
The block accepts variable-size input signals, that is, you can change the size of each input channel during simulation, but you cannot change the number of channels.
Data Types: single
| double
Complex Number Support: Yes
L — Interpolation factor input port
positive integer
Specify the interpolation factor L as a positive integer that is an integer factor of the maximum interpolation factor. For example, if you set Maximum interpolation factor to 24, then the possible values for interpolation factor are 1, 2, 3, 4, 6, 8, 12, and 24.
You can tune the interpolation factor while the simulation is running. For an example, see Interpolate Sinusoidal Signal with Tunable Interpolation Factor.
Dependencies
To enable this port:
Set Specification to
Interpolation factor
. (since R2023b)Select the Specify interpolation factor from input port parameter.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
coeffs — Prototype filter coefficients
vector
Specify the numerator coefficients of the FIR filter transfer function H(z).
You can generate the FIR filter coefficient vector, b = [b0,
b1, …,
bN], using one of the DSP System Toolbox™ filter design functions such as designMultirateFIR
, firnyquist
, firgr
or firceqrip
.
Compute the filter coefficients based on the maximum interpolation factor
Lmax instead of the interpolation factor
L. For example, if Lmax
is 24 and L is 8, and you used
designMultirateFIR
as the design function, compute the filter
coefficients using designMultirateFIR(24,1)
instead of
designMultirateFIR(8,1)
.
To act as an effective anti-imaging filter, the coefficients usually correspond to
a lowpass filter with a normalized cutoff frequency no greater than the reciprocal of
the maximum interpolation factor. To design such a filter, use the designMultirateFIR
function.
The block internally initializes all filter states to zero.
You can change the filter coefficients during simulation but the number of filter coefficients must remain constant. For an example, see Specify Filter Coefficients Through Input Port.
Dependencies
To enable this port, set the Coefficient source parameter
to Input port
.
Data Types: single
| double
Complex Number Support: Yes
Output
y — Interpolated output
vector | matrix
Interpolated output, returned as a vector or a matrix.
When you set the Specification
parameter to Interpolation factor
(since R2023b), the size of
the output signal is Lmax ×
P-by-Q, where P is the
input frame size, Q is the number of input channels, and
Lmax is the maximum interpolation
factor. However, the block computes only L ×
P-by-Q samples. The remaining samples in the
output signal are zero.
If the input is a variable-size signal, the block outputs a variable-size signal so as to maintain the interpolation factor.
When you set the
Specification parameter to Output frame
length
, the size of the output signal is
Po-by-Q, where
Po is the value you specify in the
Output frame length parameter. (since R2023b)
If the input is a variable-size signal, the block varies the interpolation factor accordingly and outputs a fixed-size signal. (since R2023b)
The complexity of the output signal depends on the complexity of the input signal and the complexity of the filter coefficients. See this table for more details.
Input Signal | Filter Coefficients | Output Signal |
---|---|---|
Real | Complex | Complex |
Real | Real | Real |
Complex | Complex | Complex |
Complex | Real | Complex |
Data Types: single
| double
Complex Number Support: Yes
Parameters
Specification — Specify mode to control interpolation factor
Interpolation factor
(default) | Output frame length
Since R2023b
Specify the mode in which you control the interpolation factor.
When you set Specification to:
Interpolation factor
–– The block maintains the interpolation factor that you specify. If the input signal frame length changes during simulation (variable-size input signal), the output frame length changes in a way as to maintain the interpolation factor L.A variable-size input generates a variable-size output.
Output frame length
–– The block maintains the output frame length that you specify. If the input signal frame length changes during simulation (variable-size input signal), the interpolation factor changes in a way as to maintain the output frame length Po.A variable-size input generates a fixed-size output.
Maximum interpolation factor — Maximum interpolation factor
24
(default) | positive integer
Specify the maximum interpolation factor Lmax as a positive integer. The interpolation factor you specify through the input port L must be a factor of the value you specify in this parameter.
When you set the
Specification parameter to Output frame
length
, the block treats the output frame length as the maximum
interpolation factor Lmax. (since R2023b)
Dependencies
To enable this port, set the
Specification parameter to Interpolation
factor
. (since R2023b)
Specify interpolation factor from input port — Specify interpolation factor from input port
on
(default) | off
When you select this parameter, you can specify the interpolation factor through the input port L. When you clear this parameter, you can specify the interpolation factor in the block dialog box through the Interpolation factor parameter.
Dependencies
To enable this parameter, set the
Specification parameter to Interpolation
factor
. (since R2023b)
Interpolation factor — Interpolation factor
24
(default) | positive integer
Specify the interpolation factor L as a positive integer that is an integer factor of the maximum interpolation factor. For example, if you set Maximum interpolation factor to 24, then the possible values for Interpolation factor are 1, 2, 3, 4, 6, 8, 12, and 24.
You can tune the interpolation factor while the simulation is running.
When you set the
Specification parameter to Output frame
length
, the block treats the ratio of the output frame length
Po to the input frame length
P as the interpolation factor L, that is,
L =
Po/P. (since R2023b)
Tunable: Yes
Dependencies
To enable this parameter:
Set the Specification parameter to
Interpolation factor
. (since R2023b)Clear the Specify interpolation factor from input port parameter.
Output frame length — Output frame length
48
(default) | positive integer
Since R2023b
Specify the output frame length Po as a positive integer. In this mode, the block maintains the frame length of the output signal at the value you specify in this parameter. If the input signal frame length changes during simulation (variable-size input signal), the interpolation factor of the block changes in a way as to maintain the output frame length.
The input frame length must be a divisor of the output frame length.
The value you specify in this parameter determines the maximum interpolation factor Lmax and the current interpolation factor L. For more details, see the Maximum interpolation factor and the Interpolation factor parameters.
Dependencies
To enable this parameter, set the Specification parameter to
Output frame length
.
Coefficient source — FIR filter coefficient source
Auto
(default) | Dialog parameter
| Input port
Specify the FIR filter coefficient source as one of the following:
Auto
–– The block designs an FIR interpolator using the interpolation factor in the Interpolation factor parameter. ThedesignMultirateFIR
function designs the filter and returns the coefficients used by the block.For more information on the filter design, see Orfanidis [1].
Dialog parameter
–– Specify the filter coefficients through the Prototype filter coefficients parameter in the block dialog box.Input port
–– Specify the filter coefficients through the coeffs input port.
Prototype filter coefficients — Prototype filter coefficients
designMultirateFIR(24,1)
(default) | vector
Specify the numerator coefficients of the FIR filter transfer function H(z).
You can generate the FIR filter coefficient vector, b = [b0,
b1, …,
bN], using one of the DSP System Toolbox filter design functions such as designMultirateFIR
, firnyquist
, firgr
or firceqrip
.
Compute the filter coefficients based on the maximum interpolation factor
Lmax instead of the interpolation factor
L. For example, if Lmax
is 24 and L is 8, and you used
designMultirateFIR
as the design function, compute the filter
coefficients using designMultirateFIR(24,1)
instead of
designMultirateFIR(8,1)
.
To act as an effective anti-imaging filter, the coefficients usually correspond to a
lowpass filter with a normalized cutoff frequency no greater than the reciprocal of the
maximum interpolation factor. To design such a filter, use the designMultirateFIR
function.
The block internally initializes all filter states to zero.
You can change the filter coefficients during simulation but the number of filter coefficients must remain constant.
Tunable: Yes
Dependencies
To enable this parameter, set the Coefficient source
parameter to Dialog parameter
.
View Filter Response — View Filter Response
button
Click this button to open the filter visualizer and display the magnitude response of the variable FIR interpolation filter. The response is based on the parameters you select in the block dialog box. To update the magnitude response while the filter visualizer is running, modify the parameters in the dialog box and click Apply.
You can configure the plot settings and the signal measurements from the interface of the visualizer.
On the Scope tab, the Configuration section allows you to modify the plot settings. Click Magnitude Phase to display the magnitude and phase response of the filter. On the Measurements tab, you can measure the signal statistics, place data cursors, and display the peak values of the selected signal.
For more details on the filter visualizer interface and its tools, see Configure Filter Visualizer.
Dependencies
You cannot view the filter response when you set the Specification parameter to Output frame
length
(since R2023b) or the Coefficient source
parameter to Input port
. To view the filter response, set
the Specification parameter to
Interpolation factor
(since R2023b) and the
Coefficient source parameter to Auto
or Dialog parameter
.
Simulate using — Type of simulation to run
Interpreted execution
(default) | Code generation
Specify the type of simulation to run. You can set this parameter to:
Interpreted execution
–– Simulate model using the MATLAB® interpreter. This option shortens startup time.Code generation
–– Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Algorithms
The FIR interpolation filter is implemented efficiently using a polyphase structure.
To derive the polyphase structure, start with the transfer function of the FIR filter:
N+1 is the length of the FIR filter.
You can rearrange this equation as follows:
Lmax is the number of polyphase components, and its value equals the maximum interpolation factor.
You can write H(z) as:
E0(zLmax), E1(zLmax), ..., ELmax-1(zLmax) are polyphase components of the FIR filter H(z).
During simulation, the algorithm reconstructs the filter H(z) based on the current interpolation factor L.
Rewriting H(z) in terms of the interpolation factor L.
where, r = Lmax/L.
Conceptually, the FIR interpolation filter contains an upsampler followed by an FIR lowpass filter H(z).
Replace H(z) with its polyphase representation.
Here is the multirate noble identity for interpolation.
Applying the noble identity for interpolation moves the upsampling operation to after the filtering operation. This move enables you to filter the signal at a lower rate.
You can replace the upsampling operator, delay block, and adder with a commutator switch. The switch starts on the first branch 0 and moves in the counterclockwise direction, each time receiving one sample from each branch. The interpolator effectively outputs L samples for every one input sample it receives. Hence the sample rate at the output of the FIR interpolation filter is Lfs.
References
[1] Orfanidis, Sophocles J. Introduction to Signal Processing. Upper Saddle River, NJ: Prentice-Hall, 1996.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2023aR2024a: Change in the default value of Simulate using parameter
The default value of the Simulate using parameter is now
Interpreted execution
. With this change, the block uses the
MATLAB interpreter for simulation by default.
R2023b: Variable FIR Interpolation block can generate fixed-size output signal for variable-size input signal
When you set Specification to Output frame
length
and specify a value for the Output frame length
parameter, the Variable FIR Interpolation block generates a fixed-size output
signal. To maintain the fixed-size at the output even when the input frame size changes
during simulation (variable-size), the block varies the interpolation factor
L.
When you set Specification to Interpolation
factor
, you specify the interpolation factor directly in the block dialog
box. In this mode, for a variable-size input signal, the block generates a variable-size
output signal. The interpolation factor L remains constant.
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)