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_T_imp.m
function [NUM,DEN,DENP]=calcul_T_imp(s,t,DEF,ei,si,h_D)

D_etude_str=get(h_D,'string');
delete(figure(7))
tmax=str2num(D_etude_str);
k=find(t<=tmax);
t=t(k);
s=s(k);
e=zeros(size(t));
e(1)=2/(DEF(4));
eint=e;
for k=1:1:DEF(3)
    eint=cumtrapz(t,eint);
end;
[F,Yn]=matrice_F(eint,s,t,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;
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);
sT='T(p) = ';
figure(4)
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','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,sT,'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;
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];
sT='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,sT,'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.32,den_fact,'color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','center','interpreter','Tex');
 PT2=get(hT2,'extent');
 xt=PT2(1)+PT2(3);
while xt<x0+w
    ht2=text(xt,0.35,'-','color','b','fontunits','normalized','fontsize',0.027,'fontweight','bold','horizontalalignment','left');
    Pt2=get(ht2,'extent');
    xt=Pt2(1)+Pt2(3);
end;
phi0=-DEF(3)*pi/2;
phiinf=(DEF(1)-DEF(2)-DEF(3))*pi/2;
if (phi0>-pi)&&(phiinf<-pi)
    [wc,kc]=critique(DEF(3),NUM,DEN);
    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')
end;
figure(5)
set(gcf,'color','w')
sys=tf(NUM,DENP);
gth=impulse(sys,t);
plot(t,s,'b')
hold on
plot(t,gth,'r')
grid on
%simulation










Contact us