Hi, I have a problem in Simulink. I should obtain the average value of a signal but I should keep this average value for the next 600 steps time. During these steps the output value is constant and it has to be updated each 600 new steps. How can I do this? Thank you so much.

댓글 수: 4

Paul
Paul 2023년 2월 23일
Some clarification is needed.
For sake of discussion, let's assum that each step is 1 second.
For t < 600, the output should be 0?
For 600 <= t < 1200, the output should be held at the average value over 0 <= t <= 600?
What should the output be from 1200 <= t < 1800? This is the key question?
Then for 1800 <= t < 2400 the output should be held at the average value of over 1200 <= t <= 1800. Correct?
Marco Minneci
Marco Minneci 2023년 2월 23일
Yes, you understood. If possible I would like also an initial condition.
Paul
Paul 2023년 2월 23일
What should the output be from 1200 <= t < 1800?
Marco Minneci
Marco Minneci 2023년 2월 23일
The output from 1200 to 1800 should be the average of the input from 600 to 1200. The key question is how can I obtain this in simulink.

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

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2023년 2월 23일
편집: Fangjun Jiang 2023년 2월 23일

2 개 추천

See attachment. Use "window length" of "6" instead of "600" to illustrate.
The build-in "Moving Average" block (it requires "DSP System Toolbox") seems like the right one to use. Need to debug further to see why the "initial condition" of the "Rate Transition" block (It behaves as a zero-order hold block) didn't take effect.
I also tried to use a MATLAB Function block to implement this. It is not too hard as long as you have a clear mind of the logic.
"InitialValue" and "WindowLength" is set in base workspace using the model PreLoadFcn callback.

댓글 수: 2

Marco Minneci
Marco Minneci 2023년 2월 23일
Ok, Perfect. It works. Thank you so much!!
Marco Minneci
Marco Minneci 2023년 4월 20일
Hi, I have another problem on the same topic. I would know if it is possible to have this particular structure but with a variable step size (the size for the solver of simulink). Thank you in advance.

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

Paul
Paul 2023년 2월 23일
편집: Paul 2023년 2월 23일

0 개 추천

If I understand the question correctly .....
Use a Discrete FIR Filter block to maintain a running average of 600 samples. Set the Sample Time parameter to the desired value or leave as -1 for inherited if the input signal is already at the desired sample time.
Connect the output of the Discrete FIR Filter block to the input of a Rate Transition Block. Set the Output Port Sample Time Options to Multiple of input port sample time. Set the Sample Time Multiple parameter to 600.

카테고리

제품

릴리스

R2021a

질문:

2023년 2월 22일

댓글:

2023년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by