Matlab function 'movmean' doesn't work on simulink

I'm designing movmean function on simulink using Matlab function block
And when i try to test the block by inputing timeseries data, the input and output of 'movmean' function is same.
I attach pics below
1) Moving Average function block
2) code of Moving Average block
3) input and output of Moving Average block (output is not computed well)

1 Kommentar

Ivo
Ivo am 22 Dez. 2025
Verschoben: Walter Roberson am 22 Dez. 2025
I have exactly the same problem. :(

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 22 Dez. 2025

0 Stimmen

This is expected if the input data is scalar (not a 1 x N or N x 1 vector or 2D array.)
Simulink feeds scalar signals to MATLAB Function Blocks one sample at a time. The moving mean of a scalar alone is the same scalar back again.
Simulink does not keep a history of all the (individually scalar) signals that have gone before, and feed the entire time history into a MATLAB Function Block.
One way to achieve the desired behaviour, is to use a DSP "buffer" block https://www.mathworks.com/help/dsp/ref/buffer.html with the overlap set to one less than the buffer size, and feed the output of the buffer block to a mean block (not a movmean block)
I suspect there might also be methods that involve transfer functions.

2 Kommentare

There is a "Moving Average" block in DSP toolbox.
Oh, that is useful!

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2017a

Gefragt:

am 6 Jan. 2022

Kommentiert:

am 22 Dez. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by