Engee documentation

Discrete Filter

Infinite impulse response (IIR) filter model.

blockType: DiscreteFilter

Path in the library:

/Basic/Discrete/Discrete Filter

Description

The Discrete Filter unit independently filters each channel of the input signal with a specified digital NIR filter. You can specify the filter structure as Direct form I, Direct form I transposed, Direct form II or Direct form II transposed.

The block implements a static filter with fixed coefficients. Each channel of the input signal is filtered independently in time.

The parameters Input processing allows you to specify how the block processes each input element. You can specify whether to process the input elements as an independent channel (Elements as channels (sample based)) or to process each input column as an independent channel (Columns as channels (frame based)). In frame-based mode, the output dimensions are equal to the input dimensions, unless you specify a matrix as a parameter Numerator coefficients. In sample-based mode, the mechanism core-modeling/vectorization-broadcast-modeling.adoc#broadcast.

The Numerator coefficients parameters specify the coefficients of the filter numerator polynomial. Parameters Denominator coefficients specifies the coefficients of the denominator polynomial of the function.

The coefficients of the numerator and denominator polynomials are set in ascending order of degrees . The Discrete Filter block allows the polynomials in (delay operator) to be used to represent a discrete system. This approach is typically used in digital signal processing (DSP). In contrast, the Discrete Transfer Fcn block allows polynomials from to be used to represent a discrete system. This approach is more common in control systems. When the numerator and denominator polynomials have the same length, the two approaches are equivalent.

Initial states

  • If the initial value is a scalar, then this initial value is used for each channel for each delay.

  • If the initial value is an array, then the dimension expansion is used.

    Consider an example. Let the initial value be [s1, s2, s3]. In that case it is a column vector, so it can be written as follows for clarity:

    [
    s1,
    s2,
    s3,
    ]

    Suppose we have one channel. Then s1 is the initial condition for the first delay, s2 is the initial condition for the second delay, etc. If there are several channels, then all this is true for each separate channel.

    The second example is [s1 s2 s3]. This is a row matrix. If the filter has three delays, then after expanding the dimensionality, the initial conditions are:

    [
    s1 s2 s3;
    s1 s2 s3;
    s1 s2 s3;
    ]

    In this case, the initial conditions for the first channel delays are [s1, s1, s1], for the second channel delays are [s2, s2, s2], and so on.

    It is possible that the number of dimensions is larger. The general rule: the first dimension corresponds to the initial conditions for different delays, the following dimensions correspond to different channels. Channels can be elements not only of a vector, but also of a matrix and arrays of higher dimensions.

The number of delays is determined as described above. For Direct form I и Direct form I transposed the number of delays for the numerator equals the length of the numerator minus 1, for the denominator equals the length of the denominator minus 1. For Direct form II и Direct form II transposed is the maximum of the denominator and numerator lengths minus 1.

Parameters Initial states sets the initial states for filter delays.

How to determine the number of initial state values to be set and how exactly to set them is described in the table below. It gives permissible initial states and the number of delay elements (filter states). The parameters Initial states can take one of four forms as described in the table.

Initial state Examples Description

Scalar

5

Each delay element for each channel is set to 5.

The block initialises all delay elements in the filter with a scalar value of

Vector or matrix (to apply different delay elements to each channel)

For a three-channel input signal and a filter with two delay elements:

] or

The delay elements for channel 1 are и .

The delay elements for channel 2 are и .

The delay elements for channel 3 are и .

Each element of the vector or matrix specifies a unique initial condition for the corresponding delay element in the corresponding channel:

  • The length of the vector must be equal to the product of the number of input channels and the number of delay elements in the filter.

  • The matrix must have the same number of rows as the number of delay elements in the filter and must have one column for each input channel.

The number of delay elements (filter states) per input channel depends on the filter structure, as shown in the following table.

Number of delay elements (filter states)
Filter structure Number of delay elements per channel

Direct form I

Direct form I transposed

  • number of zeros - 1

  • `number of poles - 1

Direct form II

Direct form II transposed

max(number of zeros, number of poles) - 1

The following tables describe the allowed initial states for different input data sizes and different number of channels, depending on the value of the parameters Input processing - frame-based processing Columns as channels (frame based) or sample-based processing Elements as channels (sample based).

Frame-based processing
Input Number of channels Permitted initial states (dialogue box) Permitted initial states (input port)

Vector column ( by 1)

Undirected vector ( )

1

scalar

Column vector ( to 1)

Vector-string ( 1 at )

Scalar

Vector-column ( to 1)

Vector-string (1 at )

Matrix ( to )

N

scalar

Vector-column ( at 1)

Vector-string ( 1 at )

Matrix ( to )

Scalar

Matrix ( at )

Processing based on samples
Input Number of channels Permissible initial states (dialogue box) Permissible initial states (input port)

Scalar

1

Scalar

Vector-column ( by 1)

Vector-string ( 1 at )

Scalar

Vector-column ( to 1)

Vector-string (1 at )

Vector row (1 at )

Vector-column ( to 1)

Undirected vector ( )

N

scalar

Column vector ( by 1)

Vector-string ( 1 at )

Matrix ( to )

Scalar

Matrix ( at )

Scalar

Vector-column ( at 1)

Vector-string ( 1 at )

Matrix ( to )

Scalar

Ports

Output

# OUT_1 — filtered signal
scalar | vector | matrix | multidimensional array

Details

Filtered output signal.

Data types

Float64.

Complex numbers support

No

Input

# u — input signal
scalar | vector | matrix | multidimensional array

Details

An input signal specified as a scalar, vector, matrix or array with any number of dimensions.

Data types

Float64.

Complex numbers support

No

# external reset — external reset signal of the unit
scalar

Details

An external signal that resets the block state to initial conditions.

Dependencies

To use this port, set the External reset parameters to any value other than . None.

Data types

Float64.

Complex numbers support

No

# Den — denominator coefficients
scalar | vector | matrix

Details

Discrete filter denominator coefficients as decreasing degrees . Use a column vector to specify the coefficients for a polynomial with a single denominator.

Dependencies

To use this port, set the parameters Denominator source to Input port.

If you are specifying denominator coefficients from the Den input port, you must select the Optimize by skipping divide by leading denominator coefficient (a0) check box . When this checkbox is selected, the block ignores the leading denominator coefficient and replaces it with 1.

Data types

Float64.

Complex numbers support

No

# Num — numerator coefficients
scalar | vector | matrix

Details

Numerator coefficients of a discrete filter as decreasing degrees . Use a column vector to specify the coefficients for a single numerator polynomial.

Dependencies

To use this port, set the parameters Numerator source to Input port.

Data types

Float64.

Complex numbers support

No

# x0 — initial states of the filter
scalar | vector | matrix

Details

Initial filter states as a scalar, vector or matrix.

Dependencies

To use this port, set the Filter Structure parameters to Direct form II or Direct form II transposed, and set the Initial states source parameters to or Input port.

Data types

Float64.

Complex numbers support

No

Parameters

Main

# Filter Structure — filter structure
Direct form I | Direct form I transposed | Direct form II | Direct form II transposed

Details

Sets the discrete structure of the IIR filter.

Values

Direct form I | Direct form I transposed | Direct form II | Direct form II transposed

Default value

Direct form II

Program usage name

FilterStructure

Tunable

No

Evaluatable

No

# Numerator source — numerator coefficient source
Dialog | Input port

Details

Indicate the source of the numerator coefficients:

  • Dialog - the numerator coefficients are specified in the parameters Numerator coefficients;

  • Input port - numerator coefficients are sent to the Num port.

Values

Dialog | Input port

Default value

Dialog

Program usage name

NumeratorSource

Tunable

No

Evaluatable

No

# Numerator coefficients — numerator coefficients
Scalar / array of real numbers

Details

Numerator coefficients of a discrete filter as decreasing degrees . Use a column vector to specify the coefficients for a single numerator polynomial.

Dependencies

To use this parameter, set the Numerator source parameter to Dialog.

Default value

[1.0]

Program usage name

Numerator

Tunable

Yes

Evaluatable

Yes

# Denominator source — source of denominator coefficients
Dialog | Input port

Details

State the source of the denominator coefficients:

  • Dialog - denominator coefficients are specified in the parameters Denominator coefficients;

  • Input port - denominator coefficients are sent to the Den port.

If you specify denominator coefficients from the Den input port, the Optimize by skipping divide by leading denominator coefficient (a0) checkbox must be selected.

Values

Dialog | Input port

Default value

Dialog

Program usage name

DenominatorSource

Tunable

No

Evaluatable

No

# Denominator coefficients — denominator coefficients
Scalar / array of real numbers

Details

Discrete filter denominator coefficients as decreasing degrees . Use a column vector to specify the coefficients for a single denominator polynomial.

If Optimize by skipping divide by leading denominator coefficient (a0) is checked, an error occurs if the parameters Denominator coefficients specify denominator coefficients and .

Dependencies

To use this parameter, set the Denominator source parameters to . Dialog.

Default value

[1.0, 0.5]

Program usage name

Denominator

Tunable

Yes

Evaluatable

Yes

# Initial states source — source of initial states
Dialog | Input port

Details

Specify the source of the initial states:

  • Dialog - initial states are specified in the parameters Initial states;

  • Input port - the initial states are received on port x0.

Dependencies

To use this parameter, set the parameters Filter Structure to Direct form II or Direct form II transposed.

Values

Dialog | Input port

Default value

Dialog

Program usage name

InitialStatesSource

Tunable

No

Evaluatable

No

# Initial states — initial states of the filter
Scalar / array of real numbers

Details

Initial filter states as a scalar, vector or matrix.

Dependencies

To use this parameter, set the Filter Structure parameters to the value of Direct form II or Direct form II transposed, and set the Initial states source parameters to or Dialog.

Default value

0.0

Program usage name

InitialStates

Tunable

Yes

Evaluatable

Yes

# Initial states on numerator side — initial states of the numerator
Scalar / array of real numbers

Details

Specify the initial states of the numerator of the filter as a scalar, vector or matrix.

Dependencies

To use this parameter, set the Filter Structure parameters to the value of Direct form I or Direct form I transposed.

Default value

0.0

Program usage name

InitialStatesNumSide

Tunable

Yes

Evaluatable

Yes

# Initial states on denominator side — initial states of the denominator
Scalar / array of real numbers

Details

Initial states of the denominator of the filter as a scalar, vector or matrix.

Dependencies

To use this parameter, set the Filter Structure parameters to the value of Direct form I or Direct form I transposed.

Default value

0.0

Program usage name

InitialDenominatorStates

Tunable

Yes

Evaluatable

Yes

# External reset — external status reset
None | Rising | Falling | Either | Level | Level hold

Details

Specify the trigger event to be used to reset states back to initial conditions. Options to select:

  • None - no reset.

  • Rising - rising edge reset.

  • Falling - falling edge reset.

  • Either - Reset on rising or falling edge.

  • Level - reset in either case:

    • When the reset signal is different from zero at the current time step.

    • When the reset signal value changes from non-zero in the previous time step to zero in the current time step.

  • Level hold - reset when the reset signal is different from zero at the current time step.

Values

None | Rising | Falling | Either | Level | Level hold

Default value

None

Program usage name

ExternalReset

Tunable

No

Evaluatable

No

# Input processing — sample-based or frame-based processing
Columns as channels (frame based) | Elements as channels (sample based)

Details

Specify whether the block performs sample-based or frame-based processing:

  • Elements as channels (sample based) - processing each element of the input signal as an independent channel.

  • Columns as channels (frame based) - processing each column of the input signal as an independent channel.

Values

Columns as channels (frame based) | Elements as channels (sample based)

Default value

Elements as channels (sample based)

Program usage name

InputProcessing

Tunable

No

Evaluatable

No

# Optimize by skipping divide by leading denominator coefficient (a0) — skip division by a0
Logical

Details

If checked, the block will not divide by in simulation. This parameters optimises the code. If you specify the denominator coefficients in the block parameters and the value , an error will occur.

If you specify denominator coefficients from the Den input port, you must select the Optimize by skipping divide by leading denominator coefficient (a0) check box . When this checkbox is selected, the block ignores the leading denominator coefficient and replaces it with 1.

If this checkbox is unchecked, the block will be fully customisable during the simulation. It will divide by during simulation.

Default value

false (switched off)

Program usage name

a0EqualsOne

Tunable

No

Evaluatable

No

# Sample time — interval between calculation steps
SampleTime (real number / vector of two real numbers)

Details

Specify the interval between calculation steps as a non-negative number. To inherit a calculation step, set this parameter to -1.

Default value

-1

Program usage name

SampleTime

Tunable

No

Evaluatable

Yes