Simulink Moving Average block not averaging according to the window length specified

3 views (last 30 days)
I've been trying to obtain the moving average value of incoming data with a specified window length of 0.5 seoncds. My model's solver is set to Fixed-Step Size with a step size of 1/250 (0.004sec). Hence, I specified a window length of 125 frames (0.004*125 = 0.5).
I'm trying to get the following conditioning:
If a condition is satisfied for 0.5 seconds, trigger a beep sound. I'm using the moving average block to 'smooth' the boolean signal over this time frame. The conditioning and beep stimulation work perfectly.
However, after data drilldown, I've come to a realization that this beep sound can be generated starting from 0.25 seconds. Am I missing something inherent about the Moving Average block? Could this be the hop size? It's worth mentioning that I'm using the Matlab R2020a release and so I have no control over the hop size.
Your read would be very much appreciated

Answers (1)

Andy Bartlett
Andy Bartlett on 13 Jan 2023
Edited: Andy Bartlett on 13 Jan 2023
Hi Shani,
Please create a simplified model that exercises the Moving Average Block in isolation.
Create a test input sequence and set the Model's simulation stop time to just long enough to get enough info the Moving Average Block's behavior.
Plot both the Moving Average Block input and output in a Scope.
Simulate the model and compare the actual output of the Moving Average Block to what you expect to happen.
If you still think the Moving Average Block is doing something wrong, please upload that simplified model and a description of specific thing you think is wrong. For example, "The actual output of the block at time 0.5 is 0.51, but I expected it to be 0.3 based on equations and reasoning ..."
One suggestion to do this experiment is to save your current model to a new name. Load that new model.
Replace the input to the Moving Average Block with just a Constant Block followed by a unit delay.
Configure the Constant Block to always output 1's with the same data type and dimensions as the original input.
Configure the Unit Delay to have the same sample time as the original input. Set the initial condition of the unit delay to value One.
Because the initial conditions inside the Moving Average Block is Zero, I would expect the block to output Zero at time Zero.
Because the input is always Ones, I would expect the block to ramp up from Zero to One and then stay at One forever.
The output will first reach One after it has executed enough times to flush out all the initial conditions of Zero. Let's call that time TimeFirstOne. The block needs enough frames coming through such that the total number of samples input equals or exceeds the Window Length.
Due to the ramping from Zero to One.
The output will be roughly 0.2 at time roughly 0.2 * TimeFirstOne.
The output will be roughly 0.5 at time roughly 0.5 * TimeFirstOne.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!