Accelerating the pace of engineering and science

# dsp.FIRDecimator System object

Package: dsp

Polyphase FIR decimator

## Description

The FIRDecimator object resamples vector or matrix inputs along the first dimension. The object reseamples at a rate M times slower than the input sampling rate, where M is the integer-valued downsampling factor. The decimation combines an FIR anti-aliasing filter with downsampling. The FIR decimator object uses a polyphase implementation of the FIR filter.

To resample vector or matrix inputs along the first dimension:

1. Define and set up your FIR decimator. See Construction.

2. Call step to resample the vector or matrix inputs according to the properties of dsp.FIRDecimator. The behavior of step is specific to each object in the toolbox.

## Construction

H = dsp.FIRDecimator returns an FIR decimator, H, which applies an FIR filter with a cutoff frequency of 0.4*pi radians/sample to the input and downsamples the filter output by factor of 2. This System object™ supports variable-size input.

H = dsp.FIRDecimator ('PropertyName',PropertyValue, ...) returns an FIR decimator, H, with each property set to the specified value.

H = dsp.FIRDecimator(DECIM, NUM, 'PropertyName',PropertyValue, ...) returns an FIR decimator, H, with the integer-valued DecimationFactor property set to DECIM, the Numerator property set to NUM, and other specified properties set to the specified values.

## Properties

 DecimationFactor Decimation factor Specify the downsampling factor as a positive integer. The FIR decimator reduces the sampling rate of the input by this factor. The size of the input along the first dimension must be a multiple of the decimation factor. The default is 2. Numerator FIR filter coefficients Specify the numerator coefficients of the FIR filter in powers of z–1. The following equation defines the system function for a filter of length L:$H\left(z\right)=\sum _{l=0}^{L-1}{b}_{l}{z}^{-l}$To prevent aliasing as a result of downsampling, the filter transfer function should have a normalized cutoff frequency no greater than 1/DecimationFactor. You can specify the filter coefficients as a vector in the supported data types. The FIR decimator does not support dfilt or mfilt objects as sources of the filter coefficients. The default is fir1(35,0.4). Structure Filter structure Specify the implementation of the FIR filter as either Direct form or Direct form transposed. The default is Direct form.

## Methods

 clone Create FIR decimator object with same property values freqz Frequency response fvtool Open filter visualization tool getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs of step method impz Impulse response isLocked Locked status for input attributes and nontunable properties phasez Unwrapped phase response release Allow property value and input characteristics changes reset Reset filter states of FIR decimator step Decimate input by integer factor

## Definitions

### Polyphase Subfilters

A polyphase implementation of an FIR decimator splits the lowpass FIR filter impulse response into M different subfilters, where M is the downsampling, or decimation factor. Let h(n) denote the FIR filter impulse response of length L and u(n) the input signal. Decimating the filter output by a factor of M is equivalent to the downsampled convolution:

$y\left(n\right)=\sum _{l=0}^{L-1}h\left(l\right)u\left(nM-l\right)$

The key to the efficiency of polyphase filtering is that specific input values are only multiplied by select values of the impulse response in the downsampled convolution. For example, letting M=2, the input values u(0),u(2),u(4), ... are only combined with the filter coefficients h(0),h(2),h(4),..., and the input values u(1),u(3),u(5), ... are only combined with the filter coefficients h(1),h(3),h(5),.... By splitting the filter coefficients into two polyphase subfilters, no unnecessary computations are performed in the convolution. The outputs of the convolutions with the polyphase subfilters are interleaved and summed to yield the filter output. The following MATLAB® code demonstrates how to construct the two polyphase subfilters for the default order 35 filter in the Numerator property and the default DecimationFactor property value of two:

```M = 2;
Num = fir1(35,0.4);
FiltLength = length(Num);
Num = flipud(Num(:));

if (rem(FiltLength, M) ~= 0)
nzeros = M - rem(FiltLength, M);
Num = [zeros(nzeros,1); Num];  % Appending zeros
end

len = length(Num);
nrows = len / M;
PolyphaseFilt = flipud(reshape(Num, M, nrows).');```

The columns of PolyphaseFilt are subfilters containing the two phases of the filter in Num. For a general downsampling factor of M , there are M phases and therefore M subfilters.

## Examples

Decimate a sum of sine waves with angular frequencies of π/4 and 2π/3 radians/sample by a factor of two. To prevent aliasing, the FIR decimator filters out the 2π/3 radians/sample component before downsampling:

```x = cos(pi/4*[0:95]')+sin(2*pi/3*[0:95]');
H = dsp.FIRDecimator;
y = step(H,x);

% View group delay of default FIR filter
fvtool(fir1(35,0.4),1,'analysis','grpdelay');
% Group delay of the default linear-phase FIR filter
% is 17.5 samples. Downsampling by a factor of
% two expect an approx. 8.75 sample delay in the output
% y with the initial filter states of zero

subplot(211);
stem(x(1:length(x)/2),'b','markerfacecolor',[0 0 1]);
title('Input Signal');
subplot(212);
stem(y,'b','markerfacecolor',[0 0 1]);
title('Output--Lowpass filtered and downsampled by 2');```

The figure shows that the delay in the decimated output is consistent with the group delay of the filter when the initial filter states are zero.

Reduce the sampling rate of an audio signal by 1/2 and play it:

```hmfr = dsp.AudioFileReader('OutputDataType',...
'single');
hap = dsp.AudioPlayer(22050/2);
hfirdec = dsp.FIRDecimator;

while ~isDone(hmfr)
frame = step(hmfr);
y = step(hfirdec, frame);
step(hap, y);
end

release(hmfr);
pause(0.5);
release(hap);```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the FIR Decimation block reference page. The object properties correspond to the block parameters, except:

• Coefficient source – The FIR decimator object does not support mfilt objects.

• Framing – The FIR decimator object only supports Maintain input frame rate

• Output buffer initial conditions – The FIR decimator object does not support this parameter.

• Rate options – The FIR decimator object does not support this parameter.

• Input processing The FIR decimator object does not support this parameter.