# LGF_FloatingAverage (FB / V3.0.2)

Author: Siemens Digital Industry

## Short description

This function calculates a moving arithmetic mean value from REAL values. This method can be used to smooth data series. The values can be read in cyclically or triggered.

### Block Interface

| LGF_FloatingAverage (FB) |
--- | --- | ---
Bool |  |  | cyclicExecution |  | average |  |  | LReal
Bool |  |  | trigger |  | windowSizeReached |  |  | Bool
LReal |  |  | value |  | error |  |  | Bool
Int |  |  | windowSize |  | status |  |  | Word
Bool |  |  | reset |  |  |  |  |

### Input parameter

Identifier | Data type | Default value | Description
--- | --- | --- | ---
cyclicExecution | Bool | false | TRUE: cyclic operation, trigger not in use
trigger | Bool | FALSE | Read in `value` with every pulse at input `trigger`
value | LReal | 0.0 | Value/s from which the moving average is to be determined.
windowSize | Int | 100 | Window length for sliding averaging in the range from 1..100. The standard value is 100.
reset | Bool | FALSE | TRUE: The block is reset and the calculation starts again.

### Output parameter

Identifier | Data type | Description
--- | --- | ---
average | LReal | Moving / Floating average
windowSizeReached | Bool | FALSE: Maximum window width not yet reached, TRUE: Maximum window width reached
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#0000 | STATUS_FINISHED_NO_ERROR Status: Execution finished without errors
16#8200 | ERR_WRONG_WINDOW_SIZE Error: Incorrect window size/width set. Set a value between 1 and 100.

## Functional description

Note
  The block `LGF_FloatingAverage` does not query the data type for the input parameter `value`. For data types other than REAL, either an implicit conversion is performed automatically or an error is generated during compilation.
  You can find further information in the Chapter “Overview of Data Type Conversion” in the Online Help section of the TIA Portal or under:
  https://support.industry.siemens.com/cs/ww/en/view/109773506/100611494667

The block calculates the (moving) mean value based on the set window width. The window width indicates the maximum number of values read in last. After the maximum number of values has been read, the output `windowSizeReached` is set and each newly read value replaces the oldest value (FIFO principle).

Two options are available for reading the values. With the input `cyclicExecution`, the values are read and calculated cyclically. With the `trigger` input, the values are read in and calculated with each pulse.

## Change log

Version & Date | Change description
--- | ---
| 01.00.00 | Siemens Industry Online Support
| 16.06.2016 | First released version
| 01.00.01 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA Portal V14 Update 1
| 01.01.00 | Siemens Industry Online Support
| 21.02.2017 | Adding variable window size for calculation Optimizing calculation algorithm
| 01.01.01 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 01.01.02 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 01.01.03 | Simatic Systems Support
| 07.11.2019 | Code refactoring, comments 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
| 16.06.2020 | refactor and simplify code
| 03.00.02 | Simatic Systems Support
| 06.04.2021 | Insert documentation