Configuration of a filter with FB_FTR_IIRSpec

This sample shows how to configure a filter of type Butterworth with the function block FB_FTR_IIRSpec.

Download: Tc3_Filter_SimpleIIRSpec.zip (*.tnzip)

Description:

Implementation:

stParams : ST_FTR_IIRSpec := ( … )
fbFilter : FB_FTR_IIRSpec := (stConfig := stParams);
IF NOT fbFilter.bError THEN
    fbFilter.Call(ADR(aSignalBuffer), SIZEOF(aSignalBuffer),
                  ADR(aFilteredSignal), SIZEOF(aFilteredSignal));
ELSE
    // if on error state, do something
    nErrorCount := nErrorCount + 1;
    // e.g. check if filter is configured
    // IF fbFilter.bConfigured THEN
    // or use ipResultMessage to check root cause
    // fbFilter.ipResultMessage
END_IF;

Observation:

Recording with TwinCAT 3 Scope shows that the amplitude of the output signals is attenuated and phase-shifted by the filter. The signal in the second channel (green) is attenuated more strongly than that in the first channel (blue, attenuation by -3 dB).

Configuration of a filter with FB_FTR_IIRSpec 1:
Signal curves of the input signals (top) and the output signals (bottom) (blue: channel 1, green: channel 2)

If the flag bReconfigure is set, the cut-off frequency is shifted to 50 Hz, which makes the amplitude of both output signals even smaller.

Configuration of a filter with FB_FTR_IIRSpec 2:
Signal curves of the input signals (top) and the output signals (bottom), if the flag bReconfigure is set (blue: channel 1, green: channel 2)

If the flag bReset is set, the internal state of the filter is deleted, i.e. past input and output values are no longer taken into account. The continuous signal curve is interrupted (at approx. 27 ms), and the filter settles again.

Configuration of a filter with FB_FTR_IIRSpec 3:
Signal curves of the input signals (top) and the output signals (bottom) when the flag bReset is set (blue: channel 1, green: channel 2)

See also: