# LGF_SmoothByPolynomFB (FB / 3.0.1)

Overview

Author: Siemens Digital Industry

## Short description

This function calculates the smoothed values by polynomial cyclically.

For smoothing, a 3rd degree polynomial is placed through five value points. The error squares of the distances between polynomial and real value are minimized. The smoothed values can be determined from the polynomial parameters obtained in this way.

The function reads-in a value with each positive edge on the `insert` input. As soon as five values have been read in, the block calculates a smoothed value and outputs it.

### Block Interface

| LGF_SmoothByPolynomFB (FB) |
--- | --- | ---
Bool |  |  | enable |  | smoothedValue |  |  | LReal
Bool |  |  | insert |  | error |  |  | Bool
LReal |  |  | value |  | status |  |  | Word

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
enable | Bool | FALSE | Activates the block. As long as enable is `TRUE`, the block can accept values on the parameter `value`.
insert | Bool | FALSE | Accepts the value at the input `value` at positive edge and outputs a `smoothedValue` if five values have been read in.
value | LReal | 0.0 | Value that is to be included in the smoothing.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
smoothedValue | LReal | The smoothed value.
error | Bool | FALSE: No error TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB 16#8000-16#FFFF: Error identification (see following Table)

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#7000 | STATUS_NO_CALL Status: No call of FB. The block waits for activation through the parameter `enable`.
16#7001 | STATUS_FIRST_CALL Status: First call of FB after enabling
16#7002 | STATUS_SUBSEQUENT_CALL Status: Processing is active. Subsequent call of FB.
16#7010 | STATUS_NOT_ENOUGH_VALUES Status: Not enough values. The block requires five (5) values to calculate a smoothed value. Transfer additional values with a positive edge on the `insert` input.

## Functional description

The 3rd degree compensation polynomial is calculated as follows:

\overline{y(n)} = \frac{1}{35} \cdot (-3 \cdot y(n-2) +12 \cdot y(n-1) +17 \cdot y(n) +12 \cdot y(n+1) -3 \cdot y(n+2))

N-4 smoothed measured values can thus be calculated from the N measured values. The output array contains the value 0 in the index (0.1, N-1, N).

These “missing” values are calculated with the following formalisms:

\overline{y(n-2)} = \frac{1}{70} \cdot (69 \cdot y(n-2) +4 \cdot y(n-1) -6 \cdot y(n) +4 \cdot y(n+1) -y(n+2)) \overline{y(n-1)} = \frac{2}{70} \cdot (2 \cdot y(n-2) +27 \cdot y(n-1) +12 \cdot y(n) -8 \cdot y(n+1) +2 \cdot y(n+2)) \overline{y(n+1)} = \frac{2}{70} \cdot (2 \cdot y(n-2) -8 \cdot y(n-1) +12 \cdot y(n) +27 \cdot y(n+1) +2 \cdot y(n+2)) \overline{y(n+2)} = \frac{1}{70} \cdot (-y(n-2) +4 \cdot y(n-1) -6 \cdot y(n) +4 \cdot y(n+1) +69 \cdot y(n+2))

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 23.11.2018 | First released version
| 1.0.1 | Simatic Systems Support
| 05.11.2019 | Bugfixes, regions, comments and constants are added
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 06.04.2021 | Insert documentation