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 and 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 and 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 for 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

The initial states of the filter 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

Parameters

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

Details

Specifies 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 — the source of the numerator coefficients
Dialog | Input port

Details

Specify the source of the numerator coefficients:

  • Dialog — the coefficients of the numerator are set in the parameter Numerator coefficients;

  • Input port — the 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

Coefficients of the numerator of a discrete filter as decreasing powers . Use the column vector to set the coefficients for a single numerator polynomial.

Dependencies

To use this parameter, set for the parameter Numerator source meaning Dialog.

Default value

[1.0]

Program usage name

Numerator

Tunable

Yes

Evaluatable

Yes

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

Details

Specify the source of the denominator coefficients:

  • Dialog — the coefficients of the denominator are set in the parameter Denominator coefficients;

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

If you specify the denominator coefficients from the input port Den, then check the box Optimize by skipping divide by leading denominator coefficient (a0).

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

Denominator coefficients of a discrete filter as decreasing powers . Use the column vector to set the coefficients for a single-denominator polynomial.

If the check box is selected Optimize by skipping divide by leading denominator coefficient (a0), an error occurs if in the parameter Denominator coefficients the coefficients of the denominator are indicated, and .

Dependencies

To use this parameter, set for the parameter Denominator source meaning 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 — the initial states are set in the parameter Initial states;

  • Input port — initial states are sent to port x0.

Dependencies

To use this parameter, set for the parameter Filter Structure meaning 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 filter states
Scalar / array of real numbers

Details

The initial states of the filter are in the form of a scalar, vector, or matrix.

Dependencies

To use this parameter, set for the parameter Filter Structure meaning Direct form II or Direct form II transposed, and for the parameter Initial states source meaning 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 filter numerator in the form of a scalar, vector, or matrix.

Dependencies

To use this parameter, set for the parameter Filter Structure meaning 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

The initial states of the denominator of the filter in the form of a scalar, vector, or matrix.

Dependencies

To use this parameter, set for the parameter Filter Structure meaning Direct form I or Direct form I transposed.

Default value

0.0

Program usage name

InitialDenominatorStates

Tunable

Yes

Evaluatable

Yes

# External reset — resetting the external state
None | Rising | Falling | Either | Level | Level hold

Details

Specify the trigger event that will be used to return the states to the initial conditions. Options to choose from:

  • None — there is no reset.

  • Rising — reset on the rising front.

  • Falling — reset on the lowering edge.

  • Either — reset on the rising or falling edge.

  • Level — reset in any of these cases:

    • When the reset signal is nonzero in 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 in 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 of 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.

For more information, see Signal processing by frames and counts.

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 you check this box, the block will not be divided into in the simulation. This parameter optimizes the code. If you specify the coefficients of the denominator in the block parameters, and the value , then an error will occur.

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

If you uncheck this box, the block will be fully configurable during the simulation. It will divide by during the simulation.

Default value

false (switched off)

Program usage name

a0EqualsOne

Tunable

No

Evaluatable

No

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

Details

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

Default value

-1

Program usage name

SampleTime

Tunable

No

Evaluatable

Yes