Main Content

dsp.VariableFIRDecimator

Polyphase FIR decimation with tunable decimation factor

Since R2024b

Description

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

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

Conceptually, the FIR decimator (as shown in the schematic) consists of an anti-aliasing FIR filter followed by a downsampler. To design an FIR anti-aliasing filter, use the designMultirateFIR function.

The FIR filter filters the data in each channel of the input using a direct-form FIR filter. The downsampler that follows downsamples each channel of filtered data by taking every M-th sample and discarding the M – 1 samples that follow. M is the value of the decimation factor. The resulting discrete-time signal has a sample rate that is 1/M times the original sample rate.

FIR decimator contains an anti-aliasing FIR filter followed by a downsampler.

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 decimator:

  1. Create the dsp.VariableFIRDecimator 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

varFIRDecim = dsp.VariableFIRDecimator returns a variable FIR decimator object with a maximum decimation factor of 24. The object designs the FIR filter using designMultirateFIR(1,24).

varFIRDecim = dsp.VariableFIRDecimator(Mmax) sets the MaxDecimationFactor property to Mmax.

varFIRDecim = dsp.VariableFIRDecimator(Mmax,M) sets the DecimationFactor property to M. The object designs the FIR filter using designMultirateFIR(1,M). The designed filter corresponds to a lowpass filter with a cutoff at π/M in radial frequency units.

example

varFIRDecim = dsp.VariableFIRDecimator(Name=Value) returns a variable FIR decimator object with additional properties specified by one or more name-value arguments. For example, varFIRDecim = dsp.VariableFIRDecimator(Specification="Output frame length") creates a variable FIR decimator 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 decimation factor, specified as one of these options:

  • "Decimation factor" –– The object maintains the specified decimation factor M. If the input signal frame length changes during simulation (variable-size input signal), the output frame length changes to maintain the decimation 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 decimation factor changes to maintain the output frame length.

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

Maximum decimation factor Mmax, specified as a positive integer. The decimation 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 input frame length as the maximum decimation factor Mmax. The input frame length must be an integer multiple of the output frame length.

Dependencies

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

Decimation factor M, specified as a positive integer that is an integer factor of the maximum decimation factor Mmax. For example, if you set MaxDecimationFactor to 24, then the possible values for DecimationFactor are 1, 2, 3, 4, 6, 8, 12, and 24.

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

When you set Specification to "Output frame length", the object treats the ratio of the input frame length P to the output frame length Po as the decimation factor M, that is, M = P/Po.

Tunable: Yes

Dependencies

To enable this property, set Specification to "Decimation 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 decimation factor changes to maintain the output frame length.

The input frame length must be an integer multiple of the output frame length.

The value you specify in this property determines the current decimation factor M. For more details, see the DecimationFactor 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 decimator 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 lowpass FIR filter in descending powers of z, specified as a vector. By default, designMultirateFIR(1,24) computes the filter coefficients with the maximum decimation factor Mmax 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 decimation factor Mmax instead of the decimation factor M. For example, if Mmax is 24 and M is 8, and you used designMultirateFIR as the design function, compute the filter coefficients using designMultirateFIR(1,24) instead of designMultirateFIR(1,8).

So that the filter can act as an effective anti-aliasing filter, the coefficients usually correspond to a lowpass filter with a normalized cutoff frequency no greater than 1/Mmax. To design such a filter, use the designMultirateFIR function.

Tunable: Yes

Dependencies

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

Usage

Description

y = varFIRDecim(x) filters and downsamples the input signal x.

example

y = varFIRDecim(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 an integer multiple 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

Decimated output, returned as a vector or a matrix.

When you set Specification to "Decimation factor", the size of the output signal is same as the size of the input signal. However, the object computes a maximum of ceil(P/M)-by-Q output samples, where P is the input frame length, Q is the number of input channels, and M is the decimation factor.

If the input is a variable-size signal, the object outputs a variable-size signal so as to maintain the decimation 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 decimation 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

Decimate a sinusoidal signal whose frame length varies during simulation. The dsp.VariableFIRDecimator object determines the frame length of the decimated output based on the value of the Specification property

Specify Decimation Factor

The two input sinusoidal signals have frame lengths of 1000 and 500, respectively. Initialize the dsp.VariableFIRDecimator object with a decimation factor of 4. Initialize the array plot to visualize the input and decimated output signals.

Fs = 44100;
sw1 = dsp.SineWave(SampleRate=Fs,...
    SamplesPerFrame=1000,Frequency=500);
sw2 = dsp.SineWave(SampleRate=Fs,...
    SamplesPerFrame=500,Frequency=500);
varDecim = dsp.VariableFIRDecimator(DecimationFactor=4)
varDecim = 
  dsp.VariableFIRDecimator with properties:

          Specification: 'Decimation factor'
    MaxDecimationFactor: 24
       DecimationFactor: 4
        NumeratorSource: 'Auto'

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

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

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

release(varDecim)

Specify Output Frame Length

Change the Specification property to 'Output frame length'. Specify the output frame length to 250. 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 decimation factor in order to maintain the frame length of the output signal. The output frame length equals the ratio of input frame length and decimation factor.

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

Decimate a sinusoidal signal by varying the decimation 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.VariableFIRDecimator object with a maximum decimation factor of 24 and a decimation factor of 8. Initialize the array plot to view the input and decimated output signals.

Fs = 44100;
sw = dsp.SineWave(SampleRate=Fs,SamplesPerFrame=100,Frequency=500);
varDecim = dsp.VariableFIRDecimator(24,8);
ap = dsp.ArrayPlot(YLimits=[-2 2],...
    ChannelNames=["Input","Decimated output"]);

Stream in the data. During simulation, change the decimation factor to 2. The span of the decimated output updates in the array plot display. You can change the decimation factor to any value that is an integer factor of the maximum decimation factor of 24.

for i = 1:1500
    input = sw();
    output = varDecim(input);
    ap(input,output);
    if i==500
        varDecim.DecimationFactor = 2;
    end
end

Specify the filter coefficients as an input to the dsp.VariableFIRDecimator object. You can vary these coefficients during simulation and see the impact on the decimator 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.VariableFIRDecimator object with a decimation factor of 4 and with the NumeratorSource property set to 'Input port'. Initialize the array plot to view the input and decimator output signals.

Fs = 44100;
sw = dsp.SineWave(SampleRate=Fs,SamplesPerFrame=100,Frequency=500);
varDecim = dsp.VariableFIRDecimator(DecimationFactor=4,...
    NumeratorSource="Input port");
ap = dsp.ArrayPlot(YLimits=[-2 2],...
    ChannelNames=["Input","Decimated 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(1,24). This function generates an effective anti-aliasing 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)]. 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 decimated output signals on an array plot. Note the impact of the change in filter coefficients on the decimated output.

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

More About

expand all

Algorithms

The FIR decimation filter is implemented efficiently using a polyphase structure. For more information on polyphase filters, see Polyphase Subfilters.

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+bMmaxzMmax+b2Mmaxz2Mmax+...+bNMmax+1z(NMmax+1))+z1(b1+bMmax+1zMmax+b2Mmax+1z2Mmax+...+bNMmax+2z(NMmax+1))+z(Mmax1)(bMmax1+b2Mmax1zMmax+b3Mmax1z2Mmax+...+bNz(NMmax+1)),

where Mmax is the number of polyphase components, and its value equals the maximum decimation factor.

You can write H(z) as

H(z)=E0(zMmax)+z1E1(zMmax)+...+z(Mmax1)EMmax1(zMmax),

where E0(zMmax), E1(zMmax), ..., EMmax-1(zMmax) are the polyphase components of the FIR filter H(z).

During simulation, the algorithm reconstructs the filter H(z) based on the current decimation factor M.

Rewriting H(z) in terms of the decimation factor M yields

H(z)=rE0(zM)+z1rEr(zM)+...+z(M1)rE(M1)r(zM),

where r = Mmax/M.

Conceptually, the FIR decimation filter contains a lowpass FIR filter followed by a downsampler.

Replace H(z) with its polyphase representation.

This is the multirate noble identity for decimation.

Applying the noble identity for decimation moves the downsampling operation to before the filtering operation. This move enables you to filter the signal at a lower rate.

You can replace the delays and the decimation factor at the input with a commutator switch. The switch starts on the first branch 0 and moves in the counterclockwise direction as shown in this diagram. The accumulator at the output receives the processed input samples from each branch of the polyphase structure and accumulates these processed samples until the switch goes to branch 0. When the switch goes to branch 0, the accumulator outputs the accumulated value.

When the first input sample is delivered, the switch feeds this input to the branch 0 and the decimator computes the first output value. As more input samples come in, the switch moves in the counter clockwise direction through branches (M−1)r, (M−2)r, and all the way up to branch 0, delivering one sample at a time to each branch. When the switch comes to branch 0, the decimator outputs the next set of output values. This process continues as data keeps coming in. Every time the switch comes to the branch 0, the decimator outputs y[m]. The decimator effectively outputs one sample for every M samples it receives. Hence the sample rate at the output of the FIR decimation filter is fs/M.

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