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;
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);
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".