Main Content

dsp.VariableFIRInterpolator

Polyphase FIR interpolation with tunable interpolation factor

Since R2024b

Description

The dsp.VariableFIRInterpolator object performs an efficient polyphase FIR interpolation with a tunable interpolation factor. You can update the interpolation factor and the filter coefficients while the simulation is running. To control the interpolation, you can specify the interpolation factor or the output frame length.

When you specify the interpolation factor, if the input frame length changes (variable-size signal) during simulation, the output frame length also changes in order to keep the interpolation factor constant. When you specify the output frame length instead of the interpolation factor, and if the input frame length changes (variable-size signal) during simulation, the interpolation factor also changes in order to keep the output frame length constant.

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.

FIR interpolator contains an upsampler followed by an anti-imaging FIR filter.

Note that the actual object algorithm implements a direct-form FIR polyphase structure, an efficient equivalent of the combined system depicted in the diagram. For more details, see Algorithms.

This object supports C and C++ code generation.

To implement the variable FIR interpolator:

  1. Create the dsp.VariableFIRInterpolator object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

varFIRInterp = dsp.VariableFIRInterpolator returns a variable FIR interpolator object with a maximum interpolation factor of 24. The object designs the FIR filter using designMultirateFIR(24,1).

varFIRInterp = dsp.VariableFIRInterpolator(Lmax) sets the MaxInterpolationFactor property to Lmax.

varFIRInterp = dsp.VariableFIRInterpolator(Lmax,L) sets the InterpolationFactor property to L. The object designs the FIR filter using designMultirateFIR(L,1). The designed filter corresponds to a lowpass filter with a cutoff at π/L in radial frequency units.

example

varFIRInterp = dsp.VariableFIRDecimator(Name=Value) returns a variable FIR interpolator object with additional properties specified by one or more name-value arguments. For example, varFIRInterp = dsp.VariableFIRInterpolator(Specification="Output frame length") creates a variable FIR interpolator object with an output frame length of 48.

example

Properties

expand all

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.

Mode to control the interpolation factor, specified as one of these options:

  • "Interpolation factor" –– The object maintains the specified interpolation factor L. If the input signal frame length changes during simulation (variable-size input signal), the output frame length changes to maintain the interpolation factor.

    A variable-size input generates a variable-size output.

  • "Output frame length" –– The object maintains the specified output frame length Po. If the input signal frame length changes during simulation (variable-size input signal), the interpolation factor changes to maintain the output frame length.

    A variable-size input generates a fixed-size output.

Maximum interpolation factor Lmax, specified as a positive integer. The interpolation factor you specify must be a factor of the value you specify in this property.

When you set Specification to "Output frame length", the object treats the output frame length as the maximum interpolation factor Lmax. The input frame length must be a divisor of the output frame length.

Dependencies

To enable this property, set Specification to "Interpolation factor".

Interpolation factor L, specified as a positive integer that is an integer factor of the maximum interpolation factor Lmax. For example, if you set MaxInterpolationFactor to 24, then the possible values for InterpolationFactor are 1, 2, 3, 4, 6, 8, 12, and 24.

You can change the interpolation factor while the simulation is running.

When you set the Specification to "Output frame length", the object 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.

Tunable: Yes

Dependencies

To enable this property, set Specification to "Interpolation factor".

Output frame length Po, specified as a positive integer. In this mode, the object maintains the frame length of the output signal at the value you specify in this property. If the input signal frame length changes during simulation (variable-size input signal), the interpolation factor changes 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 property determines the maximum interpolation factor Lmax and the current interpolation factor L. For more details, see the InterpolationFactor property description.

Dependencies

To enable this property, set Specification to "Output frame length".

FIR filter coefficient source, specified as one of these options:

  • "Auto" –– The object designs an FIR interpolator using the designMultirateFIR function. For more information on the filter design, see Orfanidis [1].

  • "Property" –– You specify the filter coefficients through the Numerator property.

  • "Input port" –– You specify the filter coefficients as an input to the object.

Numerator coefficients of the lowpass FIR filter, specified as a vector. By default, designMultirateFIR(24,1) computes the filter coefficients with the maximum interpolation factor Lmax of 24.

The transfer function H(z) of the FIR filter is given by:

H(z)=b0+b1z1+...+bNzN,

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).

So that the filter can 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.

You can change the filter coefficients during simulation but the number of filter coefficients must remain constant.

Tunable: Yes

Dependencies

To enable this property, set NumeratorSource to "Property".

Usage

Description

y = varFIRInterp(x) upsamples and filters the input signal x.

example

y = varFIRInterp(x,num) uses the coefficients vector num to filter the input signal x.

example

Input Arguments

expand all

Data input, specified as a vector or a matrix of size P-by-Q. The object 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 length) and the second dimension represents the number of channels. If the input is a one-dimensional signal, then the object interprets it as a single-channel signal.

This object accepts variable-size input signals. You can change the frame length of the signal even after you pass data to the object, but you cannot change the number of channels.

When you set Specification to "Output frame length", the input frame length P must be a divisor of the output frame length Po.

Data Types: single | double
Complex Number Support: Yes

Numerator coefficients of lowpass FIR filter in descending powers of z, specified as a vector. For more information, see the Numerator property description.

You can change the filter coefficients even after you pass data to the object, but the number of filter coefficients must remain constant. For an example, see Specify Filter Coefficients as Input in MATLAB.

Data Types: single | double
Complex Number Support: Yes

Output Arguments

expand all

Interpolated output, returned as a vector or a matrix.

When you set Specification to "Interpolation factor", the size of the output signal is L × P-by-Q samples, where P is the input frame size, Q is the number of input channels, and L is the interpolation factor.

If the input is a variable-size signal, the object outputs a variable-size signal so as to maintain the interpolation factor.

When you set Specification to "Output frame length", the size of the output signal is Po-by-Q, where Po is the value you specify in the OutputFrameLength property.

If the input is a variable-size signal, the object varies the interpolation factor accordingly and outputs a fixed-size signal.

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 SignalFilter CoefficientsOutput Signal
RealComplexComplex
RealRealReal
ComplexComplexComplex
ComplexRealComplex

Data Types: single | double
Complex Number Support: Yes

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:

release(obj)

expand all

freqzmrCompute DTFT approximation of impulse response of multirate or single-rate filter
costEstimate cost of implementing filter System object
polyphasePolyphase decomposition of multirate filter
impzImpulse response of discrete-time filter System object
coeffsReturns the filter System object coefficients in a structure
outputDelayDetermine output delay of single-rate or multirate filter
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Interpolate a sinusoidal signal whose frame length varies during simulation. The dsp.VariableFIRInterpolator object determines the frame length of the interpolated output based on the value of the Specification parameter.

Specify Interpolation Factor

The two input sinusoidal signals have frame lengths of 1000 and 500, respectively. Initialize the dsp.VariableFIRInterpolator object with an interpolation factor of 2. Initialize the array plot to visualize the input and interpolated output signals.

Fs = 44100;
sw1 = dsp.SineWave(SampleRate=Fs,...
    SamplesPerFrame=1000,Frequency=500);
sw2 = dsp.SineWave(SampleRate=Fs,...
    SamplesPerFrame=500,Frequency=500);
varInterp = dsp.VariableFIRInterpolator(InterpolationFactor=2)
varInterp = 
  dsp.VariableFIRInterpolator with properties:

             Specification: 'Interpolation factor'
    MaxInterpolationFactor: 24
       InterpolationFactor: 2
           NumeratorSource: 'Auto'

ap = dsp.ArrayPlot(YLimits=[-2 2],...
    ChannelNames=["Input","Interpolated output"]);

Stream in the data. Change the frame length of the input signal during simulation. In this mode, the object maintains the interpolation factor and varies the output frame length so that output frame length equals the product of input frame length and interpolation factor. View the input and output signals in an array plot.

for i = 1:100000
    if i < 50000
        input = sw1();
    else
        input = sw2();
    end
    output = varInterp(input);
    ap(input,output)
end

release(varInterp)

Specify Output Frame Length

Change the Specification property to 'Output frame length'. Specify the output frame length to 2000. Stream in the two input sinusoidal signals again. During simulation, when the input frame length varies, the output frame length remains constant. The object varies the interpolation factor in order to maintain the frame length of the output signal. The output frame length equals the product of the input frame length and interpolation factor.

varInterp.Specification = "Output frame length";
varInterp.OutputFrameLength = 2000;
for i = 1:100000
    if i < 50000
        input = sw1();
    else
        input = sw2();
    end
    output = varInterp(input);
    ap(input,output)
end

Interpolate a sinusoidal signal by varying the interpolation factor during simulation.

The input is a sinusoidal signal with a frequency of 500 Hz, sample time of 1/44100 s, and contains 100 samples per frame. Initialize the dsp.VariableFIRInterpolator object with a maximum interpolation factor of 24 and an interpolation factor of 4. Initialize the array plot to view the input and interpolated output signals.

Fs = 44100;
sw = dsp.SineWave(SampleRate=Fs,SamplesPerFrame=100,Frequency=500);
varInterp = dsp.VariableFIRInterpolator(24,4);
ap = dsp.ArrayPlot(YLimits=[-2 2],...
    ChannelNames=["Input","Interpolated output"]);

Stream in the data. During simulation, change the interpolation factor to 2. 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.

for i = 1:100000
    input = sw();
    output = varInterp(input);
    ap(input,output);
    if i==50000
        varInterp.InterpolationFactor = 2;
    end
end

Specify the filter coefficients as an input to the dsp.VariableFIRInterpolator object. You can vary these coefficients during simulation and see the impact on the interpolator output.

The input is a sinusoidal signal with a frequency of 500 Hz, sample time of 1/44100 s, and contains 100 samples per frame. Initialize the dsp.VariableFIRInterpolator object with an interpolation factor of 4 and with the NumeratorSource property set to 'Input port'. Initialize the array plot to view the input and interpolated output signals.

Fs = 44100;
sw = dsp.SineWave(SampleRate=Fs,SamplesPerFrame=100,Frequency=500);
varInterp = dsp.VariableFIRInterpolator(InterpolationFactor=4,...
    NumeratorSource="Input port");
ap = dsp.ArrayPlot(YLimits=[-2 2],...
    ChannelNames=["Input","Interpolated output"]);

Stream in the input signal. Specify the filter coefficients as an input to the object algorithm. Initially, the object algorithm generates the filter coefficients using designMultirateFIR(24,1). This function generates an effective anti-imaging lowpass filter with a normalized cutoff frequency no greater than 1/24.

During simulation, change the filter coefficients to [fir1(24*16-1,1/24) zeros(1,192)]*24. 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. You cannot change the number of filter coefficients while the simulation is running.

Plot the input and interpolated output signals on an array plot. Note the impact of the change in filter coefficients on the interpolated output.

for i = 1:1500
    input = sw();
    if i<500
        output = varInterp(input,designMultirateFIR(24,1));
    else
        output = varInterp(input,[fir1(24*16-1,1/24) zeros(1,192)]*24);
    end
    ap(input,output);
end

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

H(z)=b0+b1z1+...+bNzN,

where N+1 is the length of the FIR filter.

You can rearrange this equation as

H(z)=(b0+bLmaxzLmax+b2Lmaxz2Lmax+...+bNLmax+1z(NLmax+1))+z1(b1+bLmax+1zLmax+b2Lmax+1z2Lmax+...+bNLmax+2z(NLmax+1))+z(Lmax1)(bLmax1+b2Lmax1zLmax+b3Lmax1z2Lmax+...+bNz(NLmax+1)),

where Lmax is the number of polyphase components, and its value equals the maximum interpolation factor.

You can write H(z) as

H(z)=E0(zLmax)+z1E1(zLmax)+...+z(Lmax1)E(Lmax1)(zLmax),

where 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 yields

H(z)=E0(zL)+z1Er(zL)+...+z(L1)E(L1)r(zL),

where r = Lmax/L.

Conceptually, the FIR interpolation filter contains an upsampler followed by an FIR lowpass filter H(z).

FIR interpolator contains an upsampler followed by an anti-imaging FIR filter.

Replace H(z) with its polyphase representation.

This 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 MATLAB® Coder™.

Version History

Introduced in R2024b