# LGF_SimpleAveraging (FB / 1.0.0)

Overview

Author: Siemens Digital Industry

## Short description

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

### Block Interface

| LGF_SimpleAveraging (FB) |
--- | --- | ---
Bool |  |  | cyclicExecution |  | average |  |  | LReal
Bool |  |  | trigger |  | overflow |  |  | Bool
Bool |  |  | reset |  |  |  |  |
LReal |  |  | value |  |  |  |  |
USInt |  |  | windowSize |  |  |  |  |

### Input parameter

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

### Output parameter

Identifier | Data type | Description
--- | --- | ---
average | LReal | Moving / Floating average
overflow | Bool | TRUE: Overflow detected in the calculation

## Functional description

Note
  The block `LGF_SimpleAveraging` does not query the data type for the input parameter `value`. For data types other than LReal, 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) average based on the set `windowSize`. If `windowSize` is set to windowSize < 1, the value is passed through without averaging.

There are two options for reading the values:

- With the `cyclicExecution` input, the values are read and calculated cyclically.
- With the `Trigger` input, the values are read and calculated with each pulse.

If the calculation reaches the value range limits of `LReal`, the output `overflow` is set.

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Simatic Systems Support
| 18.07.2024 | First Release