# LGF_SmoothByPolynomFC (FC / V3.0.1)

Author: Siemens Digital Industry

## Short description

This function calculates the smoothed values by polynomial acyclically.

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 an array that is smoothed. N-4 smoothed measured values can be calculated from N measured values. The output array contains the value 0 in the index (0,1,N-1,N). However, replacement values can be calculated.

### Block Interface

| LGF_SmoothByPolynomFC (FC) |
--- | --- | ---
|  |  |  |  | Ret_Val |  |  | Void
|  |  |  |  | error |  |  | Bool
|  |  |  |  | status |  |  | Word
Array[*] of LReal |  |  | values |  |  | Array[*] of LReal
Array[*] of LReal |  |  | smoothedValues |  |  | Array[*] of LReal

### Output parameter

Identifier | Data type | Description
--- | --- | ---
Ret_Val | Void | Void - Function has no return 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)

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
values | Array[*] of LReal | Values that are to be included in the smoothing.
smoothedValues | Array[*] of LReal | The smoothed values.

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_FINISHED_NO_ERROR Status: Execution finished without errors
16#8400 | ERR_ARRAYS_DIFFERENT Error: The Array sizes are not equal. The arrays `values` and `smoothedValues` must have the same size.
16#8401 | ERR_NOT_ENOUGH_VALUES Error: Not enough values. The block requires five (5) values to calculate a smoothed value. Increase the size of the array at the input parameter `values`. Adapt the array on the output parameter `smoothedValues` to the new size.

## 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
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 23.11.2018 | First released version
| 01.00.05 | Simatic Systems Support
| 15.11.2019 | Regions, comments and constants are added
| 03.00.00 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 03.00.01 | Simatic Systems Support
| 06.04.2021 | Insert documentation