Code covered by the BSD License  

Highlights from
Logiciels temps réel

Logiciels temps réel

by

 

Real-time software concerning the domains of the signal processing, feedback and regulation

calcul_T2.m
function [NUM,DEN,DENP,T]=calcul_T2(e,s,t,DEF,ei,si)

h3=figure(3);
P=ecran;
pp=[1,3*P(4)/4,P(3)/4,P(4)/4];
set(gcf,'position',pp);
set(gcf,'color','w')
set(gcf,'unit','normalized')
grid off
set(gca,'color','w','xcolor','w','ycolor','w');
pause(0.1)
text(0.5,0.75,'PATIENTEZ !','color','r','fontunits','normalized','fontsize',0.1,'fontweight','bold','horizontalalignment','center')
text(0.5,0.25,'Calculs en cours...','color','r','fontunits','normalized','fontsize',0.1,'fontweight','bold','horizontalalignment','center')
drawnow
eint=e;
E=mean(e(end-10:end));
for k=1:1:DEF(3)
    eint=cumtrapz(t,eint);
end;
k0=find(t>=0);
tp=t(k0);
sp=s(k0);
eintp=eint(k0);
kf=max(find(sp<=mean(sp(end-10:end))*0.1));

%ecart_init=max(abs(sp));
ecart_init=sum(sp.^2);
ecart=0.99*ecart_init;
b=0;
while ecart<ecart_init
    ecart_init=ecart;
    b=b+10;
    epr=[zeros(b,1);eintp(1:end-b)];
    [F,Yn]=matrice_F(epr,sp,tp,DEF(1),DEF(2));
    C=inv(F'*F)*F'*Yn;
    NUM=flipud(C(1:DEF(1)+1))';
    DEN=[flipud(C(DEF(1)+2:end))',1];
    DENP=DEN;
    for k=1:1:DEF(3)
        DENP=conv(DENP,[1,0]);
    end;
    sys=tf(NUM,DENP);
    set(sys,'outputdelay',b*DEF(4))
    sth=step(sys,tp);
    ecart=sum((E*sth-sp).^2);
    %ecart=max(abs(E*sth-sp))
end;
b=max([0,b-20]);
%ecart_init=max(abs(sp));
ecart_init=sum(sp.^2);
ecart=0.99*ecart_init;
b=0;
while ecart<ecart_init
    ecart_init=ecart;
    b=b+1;
    epr=[zeros(b,1);eintp(1:end-b)];
    [F,Yn]=matrice_F(epr,sp,tp,DEF(1),DEF(2));
    C=inv(F'*F)*F'*Yn;
    NUM=flipud(C(1:DEF(1)+1))';
    DEN=[flipud(C(DEF(1)+2:end))',1];
    DENP=DEN;
    for k=1:1:DEF(3)
        DENP=conv(DENP,[1,0]);
    end;
    sys=tf(NUM,DENP);
    set(sys,'outputdelay',b*DEF(4))
    sth=step(sys,tp);
    ecart=sum((E*sth-sp).^2);
    %ecart=max(abs(E*sth-sp))
end;
b=b-1;

T=b*DEF(4);
 er=[zeros(b,1);eint(1:end-b)];
    [F,Yn]=matrice_F(epr,sp,tp,DEF(1),DEF(2));
    C=inv(F'*F)*F'*Yn;
    NUM=flipud(C(1:DEF(1)+1))';
    DEN=[flipud(C(DEF(1)+2:end))',1];
    DENP=DEN;
    for k=1:1:DEF(3)
        DENP=conv(DENP,[1,0]);
    end;
    sys=tf(NUM,DENP);
    set(sys,'outputdelay',b*DEF(4))
    sth=step(sys,tp);
delete(h3)    
figure(2)
hold on
plot(tp,E*sth+si,'g')
sn='            ';
for kl=1:1:length(NUM)
   exposant=length(NUM)-kl;
   if exposant==0
       sn=[sn,' + ',num2str(NUM(kl))];
   elseif exposant==1
       sn=[sn,' + ',num2str(NUM(kl)),'.p'];
   else
       sn=[sn,' + ',num2str(NUM(kl)),'.p^',num2str(exposant)];
   end;
end;
lnum=length(sn)-7;
sd='';
for kl=1:1:length(DEN)
   exposant=length(DEN)-kl;
   if exposant==0
       sd=[sd,' + ',num2str(DEN(kl))];
   elseif exposant==1
       sd=[sd,' + ',num2str(DEN(kl)),'.p'];
   else
       sd=[sd,' + ',num2str(DEN(kl)),'.p^',num2str(exposant)];
   end;
end;
if DEF(3)~=0
    if DEF(3)==1
        sd=['p.[',sd,']'];
    else
        alpha=num2str(DEF(3));
        sd=['p^{',alpha,'}.[',sd,']'];
    end;
end;
sd=['            ',sd];
lden=length(sd)-7;
L=max(lnum,lden);
s='T(p) = ';
figure(3)
ec=ecran;    % ecran est une fonction "maison" : ecran=get(0,'screensize');
if ec(1)<0
   ec(1)=0;
end;
set(gcf,'position',ec)
set(gcf,'color','w')
set(gcf,'unit','normalized')
set(gcf,'paperpositionmode','auto')
grid off
set(gca,'color','w','xcolor','w','ycolor','w');
pause(0.1)
text(0.5,0.9,'IDENTIFICATION (Processus avec retard)','color','r','fontunits','normalized','fontsize',0.03,'fontweight','bold','horizontalalignment','center')
text(0.05,0.8,'Signaux :','color','m','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left')
text(0.1,0.75,['Valeur initiale entre : ',num2str(ei)],'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left')
text(0.1,0.7,['Valeur initiale sortie : ',num2str(si)],'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left')
text(0.05,0.6,'Fonction de transfert :','color','m','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left')
hn=text(0.1,0.52,sn,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
hT=text(0.1,0.5,s,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
hd=text(0.1,0.45,sd,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
Pn=get(hn,'extent');
wn=Pn(3);
Pd=get(hd,'extent');
wd=Pd(3);
w=max(wn,wd);
x0=Pd(1);
xn=x0+w/2;
delete(hn)
text(xn,0.52,sn,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','center','interpreter','Tex');
delete(hd)
text(xn,0.47,sd,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','center','interpreter','Tex');
 PT=get(hT,'extent');
 xt=PT(1)+PT(3);
while xt<x0+w
    ht=text(xt,0.5,'-','color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left');
    Pt=get(ht,'extent');
    xt=Pt(1)+Pt(3);
end;
Pt=get(ht,'extent');
xt=Pt(1)+Pt(3);
sret=['.e^{-',num2str(T),'.p}'];
ht=text(xt,0.5,sret,'color','b','fontunits','normalized','fontsize',0.027,...
    'fontweight','bold','horizontalalignment','left','interpreter','Tex');
A=NUM(end);
num_fact=factorisation(NUM/A);
if ~isempty(num_fact)
    num_fact=[num2str(A),'.',num_fact];
else
    num_fact=num2str(A);
end;
den_fact=factorisation(DEN);
if DEF(3)~=0
    if DEF(3)==1
        den_fact=['p.[',den_fact,']'];
    else
        alpha=num2str(DEF(3));
        den_fact=['p^{',alpha,'}.[',den_fact,']'];
    end;
end;

num_fact=['          ',num_fact];
den_fact=['          ',den_fact];
s='T(p) = ';
hn=text(0.1,0.37,num_fact,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
hT2=text(0.1,0.35,s,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
hd=text(0.1,0.30,den_fact,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex');
Pn=get(hn,'extent');
wn=Pn(3);
Pd=get(hd,'extent');
wd=Pd(3);
w=max(wn,wd);
x0=Pd(1);
xn=x0+w/2;
delete(hn)
text(xn,0.37,num_fact,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','center','interpreter','Tex');
delete(hd)
text(xn,0.30,den_fact,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','center','interpreter','Tex');
 PT=get(hT2,'extent');
 xt=PT(1)+PT(3);
while xt<x0+w
    ht=text(xt,0.35,'-','color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left');
    Pt=get(ht,'extent');
    xt=Pt(1)+Pt(3);
end;
Pt=get(ht,'extent');
xt=Pt(1)+Pt(3);
sret=['.e^{- ',num2str(T),'.p}'];
ht=text(xt,0.35,sret,'color','b','fontunits','normalized','fontsize',0.027,...
    'fontweight','bold','horizontalalignment','left','interpreter','Tex');
[wc,kc]=critique(DEF(3),NUM,DEN,T);
text(0.05,0.25,'Rgime critique :','color','m','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left')
text(0.1,0.20,['\omega_C = ',num2str(wc),' rad/s     T_C = ',num2str(2*pi/wc),' s'],...
     'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex')
text(0.1,0.15,['K_C =',num2str(kc)],'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left','interpreter','Tex')






Contact us