Main Content

mfilt.firdecim

Direct-form FIR polyphase decimator

mfilt.firdecim will be removed in a future release. Use dsp.FIRDecimator instead.

Syntax

hm = mfilt.firdecim(m)
hm = mfilt.firdecim(m,num)

Description

hm = mfilt.firdecim(m) returns a direct-form FIR polyphase decimator object hm with a decimation factor of m. A lowpass Nyquist filter of gain 1 and cutoff frequency of π/m is designed by default. This filter allows some aliasing in the transition band but it very efficient because the first polyphase component is a pure delay.

hm = mfilt.firdecim(m,num) uses the coefficients specified by num for the decimation filter. This lets you specify more completely the FIR filter to use for the decimator.

Make this filter a fixed-point or single-precision filter by changing the value of the Arithmetic property for the filter hm as follows:

  • To change to single-precision filtering, enter

    set(hm,'arithmetic','single');
  • To change to fixed-point filtering, enter

    set(hm,'arithmetic','fixed');

Input Arguments

The following table describes the input arguments for creating hm.

Input Argument

Description

m

Decimation factor for the filter. m specifies the amount to reduce the sampling rate of the input signal. It must be an integer. When you do not specify a value for m it defaults to 2.

num

Vector containing the coefficients of the FIR lowpass filter used for decimation. When num is not provided as an input, mfilt.firdecim constructs a lowpass Nyquist filter with gain of 1 and cutoff frequency equal to π/m by default. The default length for the Nyquist filter is 24*m. Therefore, each polyphase filter component has length 24.

Object Properties

This section describes the properties for both floating-point filters (double-precision and single-precision) and fixed-point filters.

Floating-Point Filter Properties

Every multirate filter object has properties that govern the way it behaves when you use it. Note that many of the properties are also input arguments for creating mfilt.firdecim objects. The next table describes each property for an mfilt.firdecim filter object.

Name

Values

Description

Arithmetic

Double, single, fixed

Defines the arithmetic the filter uses. Gives you the options double, single, and fixed. In short, this property defines the operation mode for your filter.

DecimationFactor

Integer

Decimation factor for the filter. m specifies the amount to reduce the sampling rate of the input signal. It must be an integer.

FilterStructure

Character vector

Reports the type of filter object. You cannot set this property — it is always read only and results from your choice of mfilt object. Describes the signal flow for the filter object.

InputOffset

Integers

Contains a value derived from the number of input samples and the decimation factor — InputOffset = mod(length(nx),m) where nx is the number of input samples that have been processed so far and m is the decimation factor.

Numerator

Vector

Vector containing the coefficients of the FIR lowpass filter used for decimation.

PersistentMemory

false, true

Determines whether the filter states get restored to zeros for each filtering operation. The starting values are the values in place when you create the filter if you have not changed the filter since you constructed it. PersistentMemory set to false returns filter states to the default values after filtering. States that the filter does not change are not affected. Setting this to true allows you to modify the States, InputOffset, and PolyphaseAccum properties.

PolyphaseAccum

0 in double, single, or fixed for the different filter arithmetic settings.

Differentiates between the adders in the filter that work in full precision at all times (PolyphaseAccum) and the adders in the filter that the user controls and that may introduce quantization effects when FilterInternals is set to SpecifyPrecision.

States

Double, single, or fi matching the filter arithmetic setting.

This property contains the filter states before, during, and after filter operations. States act as filter memory between filtering runs or sessions. Double is the default setting for floating-point filters in double arithmetic.

Fixed-Point Filter Properties

This table shows the properties associated with the fixed-point implementation of the filter. You see one or more of these properties when you set Arithmetic to fixed. Some of the properties have different default values when they refer fixed point filters. One example is the property PolyphaseAccum which stores data as doubles when you use your filter in double-precision mode, but stores a fi object in fixed-point mode.

Note

The table lists all of the properties that a fixed-point filter can have. Many of the properties listed are dynamic, meaning they exist only in response to the settings of other properties. To view all of the characteristics for a filter at any time, use info(hm) where hm is a filter.

For further information about the properties of this filter or any mfilt object, refer to Multirate Filter Properties.

Name

Values

Description

AccumFracLength

Any positive or negative integer number of bits [32]

Specifies the fraction length used to interpret data output by the accumulator. This is a property of FIR filters.

AccumWordLength

Any integer number of bits [39]

Sets the word length used to store data in the accumulator.

Arithmetic

fixed for fixed-point filters

Setting this to fixed allows you to modify other filter properties to customize your fixed-point filter.

CoeffAutoScale

[true], false

Specifies whether the filter automatically chooses the proper fraction length to represent filter coefficients without overflowing. Turning this off by setting the value to false enables you to change the NumFracLength property value to specify the precision used.

CoeffWordLength

Any integer number of bits [16]

Specifies the word length to apply to filter coefficients.

FilterInternals

[FullPrecision], SpecifyPrecision

Controls whether the filter automatically sets the output word and fraction lengths, product word and fraction lengths, and the accumulator word and fraction lengths to maintain the best precision results during filtering. The default value, FullPrecision, sets automatic word and fraction length determination by the filter. SpecifyPrecision makes the output and accumulator-related properties available so you can set your own word and fraction lengths for them.

InputFracLength

Any positive or negative integer number of bits [15]

Specifies the fraction length the filter uses to interpret input data.

InputWordLength

Any integer number of bits[16]

Specifies the word length applied to interpret input data.

OutputFracLength

Any positive or negative integer number of bits [32]

Determines how the filter interprets the filter output data. You can change the value of OutputFracLength when you set FilterInternals to SpecifyPrecision.

OutputWordLength

Any integer number of bits [39]

Determines the word length used for the output data. You make this property editable by setting FilterInternals to SpecifyPrecision.

OverflowMode

saturate, [wrap]

Sets the mode used to respond to overflow conditions in fixed-point arithmetic. Choose from either saturate (limit the output to the largest positive or negative representable value) or wrap (set overflowing values to the nearest representable value using modular arithmetic.) The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always saturates. Finally, products never overflow — they maintain full precision.

RoundMode

[convergent], ceil, fix, floor, nearest, round

Sets the mode the filter uses to quantize numeric values when the values lie between representable values for the data format (word and fraction lengths).

  • ceil - Round toward positive infinity.

  • convergent - Round to the closest representable integer. Ties round to the nearest even stored integer. This is the least biased of the methods available in this software.

  • fix - Round toward zero.

  • floor - Round toward negative infinity.

  • nearest - Round toward nearest. Ties round toward positive infinity.

  • round - Round toward nearest. Ties round toward negative infinity for negative numbers, and toward positive infinity for positive numbers.

The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always round. Finally, products never overflow — they maintain full precision.

Signed

[true], false

Specifies whether the filter uses signed or unsigned fixed-point coefficients. Only coefficients reflect this property setting.

States

fi object

This property contains the filter states before, during, and after filter operations. States act as filter memory between filtering runs or sessions. The states use fi objects, with the associated properties from those objects. For details, refer to fixed-point objects in Fixed-Point Designer™ documentation. For information about the ordering of the states, refer to the filter structure section.

Filter Structure

To provide decimation, mfilt.firdecim uses the following structure. At the input you see a commutator that operates counterclockwise, moving from position 0 to position 2, position 1, and back to position 0 as input samples enter the filter.

The following figure details the signal flow for the direct form FIR filter implemented by mfilt.firdecim.

Notice the order of the states in the filter flow diagram. States 1 through 9 appear in the diagram above each delay element. State 1 applies to the first delay element in phase 2. State 2 applies to the first delay element in phase 1. State 3 applies to the first delay element in phase 0. State 4 applies to the second delay in phase 2, and so on. When you provide the states for the filter as a vector to the States property, the above description explains how the filter assigns the states you specify.

In property value form, the states for a filter hm are

hm.states=[1:9];

Examples

Convert an input signal from 44.1 kHz to 22.05 kHz using decimation by a factor of 2. In the figure that appears after the example code, you see the results of the decimation.

m = 2;                        % Decimation factor.
hm = mfilt.firdecim(m);       % Use the default filter.
fs = 44.1e3;                  % Original sample freq: 44.1kHz.
n = 0:10239;                  % 10240 samples, 0.232 second long
                              % signal.
x  = sin(2*pi*1e3/fs*n);      % Original signal--sinusoid at 1kHz.
y = filter(hm,x);             % 5120 samples, 0.232 seconds.
stem(n(1:44)/fs,x(1:44))      % Plot original sampled at 44.1 kHz.
hold on                       % Plot decimated signal (22.05 kHz)
                              % in red.
stem(n(1:22)/(fs/m),y(13:34),'r','filled')
xlabel('Time (sec)');ylabel('Signal Value')

Version History

Introduced in R2011a