% pfc_transparent
% back calculation
% transparent control of level
clear;
close;
tf = 1000;              %duration  of test
w = 1:1:tf;             %time;
tech = 1;               %sampling period
u = zeros(1,tf);
pv = u;                 %process  output
mv1 = u; mv2 = u;       %manipulated  variable
eps = u;                %error
sm = u;                 %output of model
k = 1;                  % gain of integrative process level
G = 0.07;               % gain of P(ID)
tau = 203;
am = exp(-tech/tau);
bm = 1-am;              %time constant of internal closed loop system by P(ID)
trbf = input('trbf 200 ? : '); %try 200?  %desired closed loop system by PFC: only tuning factor
lh = 1-exp(-tech*3/trbf);
fl = input('fl with back calculation = 1 /without= 0 ');
if fl == 1, 'with back calculation',  end
if fl == 0, 'without back calculation',end
mvmax=7;                %maxvalue of mv
for ii = 2:1:tf;
    eps(ii) = mv2(ii-1)-pv(ii-1);                     % error of P(ID)
    mv1(ii) = G*eps(ii);                              % manipulated variable of P(ID)
    if mv1(ii)>mvmax, mv1(ii) = mvmax;end                     % constraint on the mv
    xxx = (mv1(ii)/G)+pv(ii-1);                       % back calculation
    pv(ii) = pv(ii-1)+k*G*mv1(ii-1);                  % output of process 
    sm(ii) = sm(ii-1)*am+bm*(fl*xxx+(1-fl)*mv2(ii-1));% internal model of PFC with/without transfer of constraint
    d = (100-pv(ii))*lh+sm(ii)*bm;                    % computation of mv
    mv2(ii) = d/bm;                                   % computation of mv
end
MV1=mv1*20;
figure(1)
plot(w,MV1,'k',w,pv,'r',w,sm,'b',w,mv2,'g');
zoom
grid
title ('MV1 k / pv r / sm b / mv2 g')



