GenericFilter

genericfilter mask

GenericFilter mask

This block is a configurable filter, which supports several filter types, such as low-pass, high-pass, lag or lead, notch or a custom configured type in either continuous-time or discrete-time.

This filter solves some of the limitations of generic Simulink filter blocks:

  • When using continuous-time Simulink blocks, the generated code discretizes the continuous-time parameters in each cycle. This is computationally demanding and will increase the input-output delay of the control network. Such an increase in delay may be problematic in performance-critical applications.

  • When using discrete-time Simulink blocks, the configuration of the filter becomes more difficult. Firstly, control engineers are generally more familiar with continuous-time formulations. Secondly, the discrete-time filter parameters depend on the sample time of the system. When the sample time changes, the response of the filter changes as well.

Implementation

The filter is implemented in discrete-time as a generic filter. The discrete-time transfer function of the filter is:

\[H(z) = \frac{B_0 + B_1 z^{-1} + B_2 z^{-2}}{1 + A_1 z^{-1} + A_2 z^{-2}}\]

The filter configuration and implementation are shown below.

The filter is discretized assuming a fixed sample rate. Therefore, only fixed-step solvers are allowed. When attempting to start a Simulink® simulation with a variable-step solver, an error is displayed.

The input port Reset can be used to clear the states in the filter.

Hint

When connected to the (inverted) CloseLoopRequest signal of the command queue, the Reset input can be used to ensure that the output of the filter is zero when disabling the control loop.

Parameters and Dialog Box

Filter type

Popup box for selecting the possible filter types, defined in the table below on the right.

Discretization method

Popup box selecting the discretization method to convert from continuous-time parameters to discrete-time parameters.

Show discrete-time parameters in diagnostics view

When checked, the discrete-time parameters of the PIDLowPass block are printed to the diagnostics view. This option does not effect the generated code.

GenericFilter dialog

Filter dialog

GenericFilter-TransferFunctions

Filter type

Transfer function

Pass-through

\[1\]

1st order low pass

\[\frac{a}{\frac{1}{2 \pi f}s +1}\]

2nd order low pass

\[\frac{a(2 \pi f)^2}{s^2+4 \pi fbs + (2 \pi f)^2}\]

1st order high pass

\[\frac{a s}{s+2 \pi f}\]

2nd order high pass

\[\frac{as^2}{s^2+4 \pi fbs + (2 \pi f)^2}\]

1st order lag or lead

\[a \frac{\frac{1}{2 \pi f_1}s+1}{\frac{1}{2 \pi f_2}s+1}\]

2nd order notch

\[a \frac{ \left( \frac{1}{2 \pi f_1}s \right) ^2+\frac{2b_1}{2 \pi f_1}s+1} { \left( \frac{1}{2 \pi f_2}s \right) ^2+\frac{2b_2}{2 \pi f_2}s+1}\]

2nd order generic z

\[\frac{B_0+B_1 z^{-1}+B_2 z^{-2}}{1+A_1 z^{-1}+A_2 z^{-2}}\]

2nd order generic s

\[\frac{B_0 s^2+B_1 s+B_2}{s^2+A_1 s+A_2}\]
Parameter[0-4]

The parameters are used to configure the generic filter. The meaning of each parameter differs per filter type and is explained in the table below.

GenericFilter-parameters-2

Filter type

0

1

2

3

4

Pass-through

N/A

N/A

N/A

N/A

N/A

1st order low pass

gain (a)

Frequency [Hz] (f)

N/A

N/A

N/A

2nd order low pass

gain (a)

Frequency [Hz] (f)

Damping (b)

N/A

N/A

1st order high pass

gain (a)

Frequency [Hz] (f)

N/A

N/A

N/A

2nd order high pass

gain (a)

Frequency [Hz] (f)

Damping (b)

N/A

N/A

1st order lag or lead

gain (a)

Pole frequency [Hz] (f2)

N/A

Zero frequency [Hz] (f1)

N/A

2nd order notch

gain (a)

Pole frequency [Hz] (f2)

Pole damping (b2)

Zero frequency [Hz] (f1)

Zero damping (b1)

2nd order generic Z

B0

B1

B2

A1

A2

2nd order generic S

B0

B1

B2

A1

A2

Note

Some combinations of parameters yield invalid filter configurations. For example, the FirstOrderLowPass filter with a cut-off frequency of zero leads to a division by zero. Such filter configurations are not allowed. Invalid parameters are handled as follows:

  • When starting simulation: An error is displayed and the simulation is not started.

  • During simulation: A warning is displayed in the Diagnostic Viewer and in the Command Window. The simulation is proceeded with the last valid set of parameters.

Data Type Support

Input ports
The input port Input accepts only signals of type single.
The input port Reset accepts only signals of type boolean.
Dialog parameters

All dialog parameters must be of type single.

Note

Entering double values will give a warning that precision loss may occur.

Code generation

Filter name

The filter name is inherited from Simulink. To ensure that all filters have a unique name in PMP, the filter name is prefixed with the name of its parent subsystems. For example, the name of filter GenericFilter1 in Subsystem modelname/SubsystemFoo/SubsystemBar becomes SubsystemFoo_SubsystemBar_GenericFilter1.

Signals

The following signals are generated in PMP:

GenericFilter-signals

Signal Name

Access

Data Type

Description

Type

RW

Float

Selected filter type.

Parameter0

RW

Float

Continuous-time generic filter parameter 0.

Parameter1

RW

Float

Continuous-time generic filter parameter 1.

Parameter2

RW

Float

Continuous-time generic filter parameter 2.

Parameter3

RW

Float

Continuous-time generic filter parameter 3.

Parameter4

RW

Float

Continuous-time generic filter parameter 4.

ParameterB0

R

Float

Discrete-time generic filter parameter B0.

ParameterB1

R

Float

Discrete-time generic filter parameter B1.

ParameterB2

R

Float

Discrete-time generic filter parameter B2.

ParameterA1

R

Float

Discrete-time generic filter parameter A0.

ParameterA2

R

Float

Discrete-time generic filter parameter A1.