FC 165 - Moving Average

The moving average function code computes a moving average from n samples taken at a defined interval. The sample buffer fills with an input value at the end of each cycle. At every sample interval, the current input value replaces the oldest value in the buffer. At each sample interval, a new average is calculated.

 

 

Outputs:

Blk

Type

Description

N

R

Sum of samples divided by the number of samples

 

 

Specifications:

Spec

Tune

Default

Type

Range

Description

S1

N

5

I

Note 1

Block address of averaged value

S2

N

1

I

1 - 255

Number of samples in moving average

S3

Y

1.000

R

0.0 - 9.2E18

Sample interval in seconds

S4

N

1

I

0 or 1

Output track switch:

0 = track

1 = normal

 

NOTES:

1. Maximum values are:9,998 for the BRC-100, IMMFP11/12 and 31,998 for the HAC

 

 

 

165.1   Explanation

 

 

The moving average block calculates the average of n values by dividing the sum of the samples by the number of samples. It operates in two modes, normal and track. In the normal mode, the block reads a new input, discards the oldest sample, and calculates a new average each time the sample interval passes. In the track mode, the output equals the input. At each cycle, the buffer fills with the tracked value.

 

The sample interval and the number of samples used are configurable. The samples are stored in a first in first out (FIFO) buffer. During module startup, the FIFO buffer fills with the input values from each scan cycle. After startup, the moving average function code computes the starting average with the first sample interval. Therefore, the first output is the same as the input (first sample divided by one), the second output is the average of the first two inputs (first and second sample divided by two), and so on.

 

Example:

If n equals five at power up and the input equals 2.0:

 

n = 1 valid sample

 

 

 

 

On second scan the input equals 4.0:

n = 2 valid samples

 

 

 

165.1.1  Specifications

 

S1 - X

Value of the current input.

 

S2 - N

Number of samples used in the average calculation.

 

S3 - INT

Sample interval in seconds. This specification defines the length of time between inputs. It also defines the length of time between calculations, because a new average is calculated each time a new value is added.

 

S4 - TRCK

Block address of track input. In the track mode, the output tracks the input; there is no operation performed on the input. The tracked values fill the input buffer, but they are not averaged. In the normal mode, the input feeds into a sample buffer and a new output is calculated each time an input is entered.

0 = track

1 = normal

 

 

 

165.1.2  Output

 

N

Sum of the samples divided by the number of samples in the normal mode. In the track mode, the output equals the input. In both modes, the current calculated values are not retained.

 

NOTE: In normal mode, the moving average output is valid only after n samples have been processed.