Matlab function 'movmean' doesn't work on simulink

조회 수: 28 (최근 30일)
Lee Leo
Lee Leo 2022년 1월 6일
댓글: Walter Roberson 2025년 12월 22일 18:04
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
Ivo
Ivo 2025년 12월 22일 13:01
이동: Walter Roberson 2025년 12월 22일 17:28
I have exactly the same problem. :(

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2025년 12월 22일 17:46
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
Fangjun Jiang
Fangjun Jiang 2025년 12월 22일 17:56
There is a "Moving Average" block in DSP toolbox.
Walter Roberson
Walter Roberson 2025년 12월 22일 18:04
Oh, that is useful!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by