MATLAB Answers

Simulink control with moving average

12 views (last 30 days)
Lorenzo Balestra
Lorenzo Balestra on 21 Jan 2021
Answered: Paul on 21 Jan 2021
Hello everyone,
I am working on the control for a hybrid power-plant. I have defined a profile that represents the IDEAL power I would like to deliver (blue line called OP). The diesel generators I am controlling do not like the high frequency changes in the power demand, and is better to control them with smooth transitions. For this purpose i have plotted two smoother profiles (red line and green line).
The red line is obtained by averaging the 5 values in the instants before the present instant t, to obtain the load value for the diesel generator at t:
Power(t) = (Power(t-5) + Power(t-4) + Power(t-3) + Power(t-2) + Power(t-1))/5
Power_1_avg = OP;
Power_1_w_avg = OP;
for i = 6 : l_1
Power_1_avg(i) = (OP(i-5) + OP(i-4) + OP(i-3) + OP(i-2) + OP(i-1))/5; % Simple average
Power_1_w_avg(i) = (OP(i-5)*100 + OP(i-4)*200 + OP(i-3)*300 + OP(i-2)*400 + OP(i-1)*500)/(100+200+300+400+500); % Weighted average
end
The green line is obtained in the same way, just using a weighted average. The first 5 values of all the profiles (blue, red and green line) are just the same and are not averaged. It is not possible to use a simple 5 point moving average as we do not know the power demand in the future, when controlling real diesel generators, and so the load value at the instant t has to be based on the previous demand. To clarify, the blue line imposed by me just represents a guy with a pedal on the accellerator requiring power, and the red or green line is what the system allows him to have.
Now I am trying to implement a way to control the diesel generator model in simulink. I have the blue profile in the model as a repeating sequence interpolated, and i would like to perform the average as i explained above, so that i can send the value Power to the diesel generator.
My problem is how to create a 5 point buffer so that i can average the values in the buffer? The buffer should work in a last in first out manner so that when a new number enters the buffer, the last one is "pushed out".

  0 Comments

Sign in to comment.

Accepted Answer

Paul
Paul on 21 Jan 2021
A difference equation of the form
y(k)=(c0*u(k)+c1*u(k-1)+c2*u(k-2)+c3*u(k-4)+c4*u(k-4))/D
can be implemeted with one of the blocks in the Discrete Library, like the Discrete Filter or the Discrete FIR Filter, assuming sampling and averaging at a fixed sampe rate.

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!