%pfc_unstable_zero
%  MIMO PFC 2 x 2  
%control of   H= (1+T1.p)/(1+T2.p) (T2 >0  T1>0 or T1<0  ) transfer function
clear all
close all
tech=1;
tf=800;w=1:1:tf;
%process
T1=-40; %num  time constant
T2=100; %den    
A0=T1/T2;B0=1-A0;        %expansion direct transfer
a2=exp(-tech/T2);b2=1-a2;
%definition of variables
e=zeros(1,tf);sp=e;sm=e;sm0=e;sp1=e;spm=e;S=e;smb=e;
spd=e;ss=e;SS=e;sm1=e;MV=e;CV=e;pert=e;
%control
h=150;%>43 coincidence point further than the dip !
lh=1-exp(-tech*h*3/120);b2h=1-a2^h;
for ii=3:1:tf
   if ii>500;pert(ii)=20;else;pert(ii)=0;end 
   %process
   sm0(ii)=sm0(ii-1)*a2+b2*(MV(ii-1))*B0;
   CV(ii)=A0*MV(ii-1)+sm0(ii)+pert(ii);
   smd(ii)=A0*MV(ii-1);
   %control
   d=(100-CV(ii))*lh+sm0(ii)*b2h+smd(ii);
   MV(ii)=d/(A0+b2h*B0);
   %MV(ii)=100;
  %
end

plot(w,MV*1,'k',w,CV,'r',w,ones(1,tf)*100,'k',w,ones(1,tf)*0,'k',w,pert,'b');
grid 
zoom
title(' CONTROL UNSTABLE ZERO / H = (1-50.p)/(1+100.p)')


text ( 75 ,75, 'CV ')
text (75,120,'MV ')
text (750,-90,'sec ')
text (555,30,'DIST ')




