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

trace_bode.m
function trace_bode(courbes,~,br_puls,val_max,val_min,nb_pt,super,nom_systeme,~,NUM,DEN,type_de_filtre,FA,FP,Amax,Amin)


couleur=['b','k','r','g','m','c','y','b','k','r','g','m','c','y','b','k','r','g','m','c','y'];
grille='k';
mini=str2num(val_min);
maxi=str2num(val_max);
nb=str2num(nb_pt);
if br_puls
	w=logspace(log10(mini),log10(maxi),nb);
else
	w=logspace(log10(2*pi*mini),log10(2*pi*maxi),nb);

end;
set_param(nom_systeme,'SolverPrmCheckMsg','none')
%***********************************************************
%           Test : y a-t-il un bloc AOp_SimPower ?
%***********************************************************
liste=get_param(nom_systeme,'blocks');
listestr=char(liste);
[nl,nc]=size(listestr);
for kbloc=1:1:nl
    test=findstr(listestr(kbloc,:),'AOp_SimPower');
    if test
        nom_systeme_bloc=deblank(listestr(kbloc,:));
        nom_systeme_bloc=[nom_systeme,'/',nom_systeme_bloc];
        set_param(nom_systeme_bloc,'LinkStatus','inactive')
    end;
end;    
[a b c d]=linmod(nom_systeme);
%ret=retard;
[m p w]=bode(a,b,c,d,1,w);
[npt nout]=size(m);
ktx=floor(nb/nout);
g=20*log10(m);
T=polyval(NUM,1i*w)./polyval(DEN,1i*w);
G=20*log10(abs(T));
PHI=dephasage_continu(angle(T)*180/pi);
delta_phi=p(1)-PHI(1);
while abs(delta_phi)>180
    PHI=PHI+360*sign(delta_phi);
    delta_phi=p(1)-PHI(1);
end;
if courbes(1)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom_systeme,' - GAIN'];
	ki=1;
	while ((nouveau) & (ki<=length(f)))
		if strcmp(get(f(ki),'name'),nom_fig)
			nouveau=0;
			fig=f(ki);
		end;
	ki=ki+1;
	end;
	if nouveau
		fig=figure('name',nom_fig);
		vminig=[];
		vmaxig=[];
	end;
	set(0,'currentf',fig);
	ax=get(gca,'chil');
	lax=length(ax);
	kax=0;
	for ka=1:1:lax
		s=get(ax(ka),'type');
		if strcmp(s,'line')
			kax=kax+1;
		end;
	end;
	if super
		hold on
        v=get(gcf,'userdata');
        vminig=v(3);
        vmaxig=v(4);
	else 
		hold off
		vminig=[];
		vmaxig=[];
	end;
	for k=1:1:nout
		if br_puls
			semilogx(w,20*log10(m(:,k)),couleur(k+kax),w,G,'k')
			xleg='\omega (en rad/s)';
			xtx=w(k*ktx-kax);
		else
			semilogx(w/(2*pi),20*log10(m(:,k)),couleur(k+kax),w/(2*pi),G,'k')
			xleg='F (en Hz)';
			xtx=w(k*ktx-kax)/(2*pi);
		end;
		ytx=20*log10(m(k*ktx-kax,k));
		if ~(nout==1)
			text(xtx,ytx,num2str(k),'color',couleur(k+kax));
		end;
		hold on
		vmig=min([min(20*log10(m(:,k))),min(G)]);
		vmag=max([max(20*log10(m(:,k))),max(G)]);
		vminig=[vminig,vmig];
		vmaxig=[vmaxig,vmag];
	end;
	vming=min(vminig);
	vmaxg=max(vmaxig);
	set(gca,'xlim',[mini maxi],'xgrid','on','xcolor',grille,'xscale','log',...
	     'ylim',[vming vmaxg],'ygrid','on','ycolor',grille)
	xlabel(xleg)
	ylabel('gain (en dB)')
	v=axis;
    grid on
	set(gcf,'userdata',v);
    if nouveau
        hold on
        if br_puls
            FGP=2*pi*FP;
            FGA=2*pi*FA;
        else
            FGP=FP;
            FGA=FA;
        end;
        switch type_de_filtre
    case 'PL'
    semilogx([v(1),FGP],[Amax,Amax],'r','linewidth',2)
    semilogx([FGP,FGP],[v(3),Amax],'r','linewidth',2)
    semilogx([FGA,v(2)],[Amin,Amin],'r','linewidth',2)
    semilogx([FGA,FGA],[v(4),Amin],'r','linewidth',2)
    loc='NorthEast';
      case 'PH'
    semilogx([v(2),FGP],[Amax,Amax],'r','linewidth',2)
    semilogx([FGP,FGP],[v(3),Amax],'r','linewidth',2)
    semilogx([FGA,v(1)],[Amin,Amin],'r','linewidth',2)
    semilogx([FGA,FGA],[v(4),Amin],'r','linewidth',2)
    loc='NorthWest';
            case 'PB'
        semilogx([FGP(1),FGP(2)],[Amax,Amax],'r','linewidth',2)
    semilogx([FGP(1),FGP(1)],[v(3),Amax],'r','linewidth',2)
    semilogx([FGP(2),FGP(2)],[v(3),Amax],'r','linewidth',2)
    semilogx([FGA(2),v(2)],[Amin,Amin],'r','linewidth',2)
     semilogx([FGA(1),v(1)],[Amin,Amin],'r','linewidth',2)
    semilogx([FGA(1),FGA(1)],[v(4),Amin],'r','linewidth',2)
    semilogx([FGA(2),FGA(2)],[v(4),Amin],'r','linewidth',2)
    loc='NorthEast';          
        end;
        legend('SIMULATION','COURBE THEORIQUE','GABARIT','location',loc)
        if super
		hold on
	else 
		hold off
		vminig=[];
		vmaxig=[];
	end;
    end;
	zoom on
    set(gcf,'color','w')
end;
if courbes(2)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom_systeme,' - ARGUMENT'];
	ki=1;
	while ((nouveau) & (ki<=length(f)))
		if strcmp(get(f(ki),'name'),nom_fig)
			nouveau=0;
			fig=f(ki);
		end;
	ki=ki+1;
	end;
	if nouveau
		fig=figure('name',nom_fig);
		vminip=[];
		vmaxip=[];
	end;
	set(0,'currentf',fig);
	ax=get(gca,'chil');
	lax=length(ax);
	kax=0;
	for ka=1:1:lax
		s=get(ax(ka),'type');
		if strcmp(s,'line')
			kax=kax+1;
		end;
	end;
	if super
		hold on
         v=get(gcf,'userdata');
        vminip=v(3);
        vmaxip=v(4);
	else 
		hold off
		vminip=[];
		vmaxip=[];
	end;
	for k=1:1:nout
		if br_puls
			semilogx(w,p(:,k),couleur(k+kax),w,PHI,'k')
			xleg='\omega (en rad/s)';
			xtx=w(k*ktx-kax);
		else
			semilogx(w/(2*pi),p(:,k),couleur(k+kax),w/(2*pi),PHI,'k')
			xleg='F (en Hz)';
			xtx=w(k*ktx-kax)/(2*pi);
		end;
		ytx=p(k*ktx-kax,k);
		if ~(nout==1)
			text(xtx,ytx,num2str(k),'color',couleur(k+kax))
		end;
		hold on
           legend('SIMULATION','COURBE THEORIQUE')
		vmip=min(p(:,k));
		vmap=max(p(:,k));
		vminip=[vminip,vmip];
		vmaxip=[vmaxip,vmap];
	end;
	vminp=min(vminip);
	vmaxp=max(vmaxip);
	set(gca,'xlim',[mini maxi],'xgrid','on','xcolor',grille,'xscale','log',...
	     'ylim',[vminp vmaxp],'ygrid','on','ycolor',grille)
	xlabel(xleg)
	ylabel('argument (en )')
	v=axis;
    grid on
	set(gcf,'userdata',v);
	zoom on
	if nouveau
		echelles;
	end;
    set(gcf,'color','w')
end;
if courbes(3)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom_systeme,' - GAIN et ARGUMENT'];
	ki=1;
	while ((nouveau) & (ki<=length(f)))
		if strcmp(get(f(ki),'name'),nom_fig)
			nouveau=0;
			fig=f(ki);
		end;
	ki=ki+1;
	end;
	if nouveau
		fig=figure('name',nom_fig);
		vmini2g=[];
		vmaxi2g=[];
		vmini2p=[];
		vmaxi2p=[];
	end;
	set(0,'currentf',fig);
	 if super
		hold on
	 else 
		hold off
		vmini2g=[];
		vmaxi2g=[];
		vmini2p=[];
		vmaxi2p=[];
	 end;
	subplot(2,1,1)
	ax=get(gca,'chil');
	lax=length(ax);
	kax=0;
	for ka=1:1:lax
		s=get(ax(ka),'type');
		if strcmp(s,'line')
			kax=kax+1;
		end;
	end;
	for k=1:1:nout
		if br_puls
			semilogx(w,20*log10(m(:,k)),couleur(k+kax))
			xleg='\omega (en rad/s)';
			xtx=w(k*ktx-kax);
		else
			semilogx(w/(2*pi),20*log10(m(:,k)),couleur(k+kax))
			xleg='F (en Hz)';
			xtx=w(k*ktx-kax)/(2*pi);
		end;
		ytx=20*log10(m(k*ktx-kax,k));
		if ~(nout==1)
		text(xtx,ytx,num2str(k),'color',couleur(k+kax))
		end
		hold on
		vmi2g=min(20*log10(m(:,k)));
		vma2g=max(20*log10(m(:,k)));
		vmini2g=[vmini2g,vmi2g];
		vmaxi2g=[vmaxi2g,vma2g];
	end;
	vmin2g=min(vmini2g);
	vmax2g=max(vmaxi2g);
	set(gca,'xlim',[mini maxi],'xgrid','on','xcolor',grille,'xscale','log',...
	     'ylim',[vmin2g vmax2g],'ygrid','on','ycolor',grille)
	xlabel(xleg)
	ylabel('gain (en dB)')
    grid on
	zoom on
	subplot(2,1,2)
	ax=get(gca,'chil');
	lax=length(ax);
	kax=0;
	for ka=1:1:lax
		s=get(ax(ka),'type');
		if strcmp(s,'line')
			kax=kax+1;
		end;
	end;
	for k=1:1:nout
		if br_puls
			semilogx(w,p(:,k),couleur(k+kax))
			xleg='\omega (en rad/s)';		
			xtx=w(k*ktx-kax);
		else
			semilogx(w/(2*pi),p(:,k),couleur(k+kax))
			xleg='F (en Hz)';
			xtx=w(k*ktx-kax)/(2*pi);
		end;
		ytx=p(k*ktx-kax,k);
		if ~(nout==1)
		text(xtx,ytx,num2str(k),'color',couleur(k+kax))
		end
		hold on
		vmi2p=min(p(:,k));
		vma2p=max(p(:,k));
		vmini2p=[vmini2p,vmi2p];
		vmaxi2p=[vmaxi2p,vma2p];
	end;
	vmin2p=min(vmini2p);
	vmax2p=max(vmaxi2p);
	set(gca,'xlim',[mini maxi],'xgrid','on','xcolor',grille,'xscale','log',...
	     'ylim',[vmin2p vmax2p],'ygrid','on','ycolor',grille)
	xlabel(xleg)
	ylabel('argument (en )')
    grid on
	zoom on
    set(gcf,'color','w')
end;

Contact us