필터 지우기
필터 지우기

How can I calculate running mean over 40 samples in Simulink?

조회 수: 6 (최근 30일)
Igor Batoukhtine
Igor Batoukhtine 2016년 4월 16일
답변: Ced 2016년 4월 16일
Hello,
I've got the following signal simulated in Simulink:
No I would like to return the average of this signal over a sample time of 40 secondes and running. So average 1 would be over the periode 0-40. Average 2 over the period 1-41, average 3 over 2-42 etc. In Matlab I did this with the following code:
if (tijd >= Reistijd)
inc = inc + 1;
ii = ii + 1;
avgrho(ii) = mean(rho_measurement(inc-Reistijd:inc));
end

채택된 답변

Ced
Ced 2016년 4월 16일
What you are describing is known as a moving average filter.
If you want to do this in simulink (i.e. while running the simulation), you could implement it as a filter. You can create it with blocks, but for a window of 40 samples, that would be a pain. I would thus suggest to either use an S function block, or define the filter coefficients
N = 40;
b = ones(1,N)/N;
a = 1
and use a transfer function block. There is also a Simulink tutorial on how to create an actual simulink "object" for a moving average filter, see here
If you want to do this as post-processing in Matlab, there are plenty of ways to do this. One possibility is to view it as a convolution, i.e.
N = 40;
t = linspace(0,2,100);
x_raw = sin(2*pi*t) + randn(1,length(t));
mav_filt = ones(1,N)/N;
x_mav = conv(x_raw,mav_filt,'same');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by