Moving average
In this example, the way that the Condition Monitoring library is used is shown by the calculation of a moving average as an example. The FB_CMA_MovingMean block is used here. Similarly, a moving standard deviation, skewness, and excess can also be calculated using the FB_CMA_MovingStandardDeviation, FB_CMA_MovingSkew, and FB_CMA_MovingExcess function blocks.
The source code for the sample is available for download from here:MovingMoments_Sample.zip
Block diagram
Program parameters
This table contains a list of the parameters that are important for configuring the function blocks.
Oversamples/buffer length | 10 |
Population (stream) | 100 |
Stack length (spectrum) | 400 |
Window length | 800 |
FFT length | 1024 |
FFT result length | 513 |
Explanations
The scope project contained in this sample shows the calculated moving averages of a sine wave and a pulse in a streaming context in a YT chart. In order to ensure that the output data is processed correctly, it is important to consider how time influences the averaging. This is explained below.
- Sine: The calculated mean value is shown here with a time offset of -5000 us. This value results from half the internal buffer length (
nPopulation
), taking into account the cycle time of 1 ms (see FastTask) and the oversampling factor. - Impulse: The averaging of the impulse function shows the inertia of the moving average. The pulse length is set to 20 ms here. Dependent on the configuration (cycle time, oversampling), the calculated moving average attains a stable value 10 ms after every pulse.
Furthermore, the project includes the display of a calculated averaged spectrum in a separate array bar chart. This shows a magnitude spectrum for a range from 0 to 1 kHz. The current spectrum is shown as a bar chart, the moving average is shown as a continuous line.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4022.25 | PC or CX (x86, x64) | Tc3_CM, Tc3_CM_Base |