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_mc2.m
function trace_bode_mc(courbes,br_freq,br_puls,val_max,val_min,nb_pt,super,nom,bloc,NUM,DEN,type_de_filtre,FA,FP,Amax,Amin,nb_simul,serie)

couleur=['b','k','r','g','m','c','y','b','k','r','g','m','c','y','b','k','r','g','m','c','y',...
    'b','k','r','g','m','c','y','b','k','r','g','m','c','y','b','k','r','g','m','c','y',...
    '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,'SolverPrmCheckMsg','none')
switch serie
    case 2
        precision=0.2;
    case 3
        precision=0.1;
    case 4
        precision=0.05;
    case 5
        precision=0.02;
    case 6
        precision=0.01;
end;        
n=find_system(gcs,'findall','on');
k=find(strcmp(get_param(n,'type'),'block'));
b=n(k);
s='etage_numero_';
longs=length(s);
k=find(strncmp(get_param(b,'name'),s,longs));
etage=b(k);
val_init=cell(size(etage));
val_init=get_param(etage,'MaskValueString');
s_ao= '|200|3|13|15|1000000|200';
l_val_init=length(val_init);
for k_init=1:1:l_val_init
     sss=char(val_init(k_init));
     ss=[];
     k=1;
     while ~strcmp(sss(k:end),s_ao)
        ss=[ss,sss(k)];
        k=k+1;
     end;
     val_init(k_init)=cellstr(ss);
end;     
for nouvelle_simul=1:1:nb_simul
    rand('state', sum(100*clock));
    for k_alea=1:1:l_val_init
        sss=char(val_init(k_alea));
        barre=find(sss=='|');
        debut=1;
        kbarre=1;
        salea=[];
        while kbarre<=length(barre)
            valn=str2num(sss(debut:barre(kbarre)-1));
            val=num2str(valn*(1+(2*rand-1)*precision));
            debut=barre(kbarre)+1;
             kbarre=kbarre+1;
            salea=[salea,val,'|'];
        end;
         valn=str2num(sss(debut:end));
         val=num2str(valn*(1+(2*rand-1)*precision));
         salea=[salea,val,'|'];
        salea=[salea,s_ao(2:end)]
        set_param(etage(k_alea),'MaskValueString',salea)
    end;
%***********************************************************
%           Test : y a-t-il un bloc AOp_SimPower ?
%***********************************************************
liste=get_param(nom,'blocks');
listestr=char(liste);
[nl,nc]=size(listestr);
for kbloc=1:1:nl
    test=findstr(listestr(kbloc,:),'AOp_SimPower');
    if test
        nom_bloc=deblank(listestr(kbloc,:));
        nom_bloc=[nom,'/',nom_bloc];
        set_param(nom_bloc,'LinkStatus','inactive')
    end;
end;    
[a b c d]=linmod(nom);
%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,i*w)./polyval(DEN,i*w);
G=20*log10(abs(T));
PHI=dephasage_continu(angle(T)*180/pi);
if courbes(1)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom,' - 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
        if ~nouveau
        v=get(gcf,'userdata');
        vminig=v(3);
        vmaxig=v(4);
        end;
	else 
		hold off
		vminig=[];
		vmaxig=[];
	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
		vmig=min(20*log10(m(:,k)));
		vmag=max(20*log10(m(:,k)));
		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;
	set(gcf,'userdata',v);
    if nouveau
        hold on
        switch type_de_filtre
    case 'PL'
    semilogx([v(1),FP],[Amax,Amax],'r','linewidth',2)
    semilogx([FP,FP],[v(3),Amax],'r','linewidth',2)
    semilogx([FA,v(2)],[Amin,Amin],'r','linewidth',2)
    semilogx([FA,FA],[v(4),Amin],'r','linewidth',2)
    loc='NorthEast';
      case 'PH'
    semilogx([v(2),FP],[Amax,Amax],'r','linewidth',2)
    semilogx([FP,FP],[v(3),Amax],'r','linewidth',2)
    semilogx([FA,v(1)],[Amin,Amin],'r','linewidth',2)
    semilogx([FA,FA],[v(4),Amin],'r','linewidth',2)
    loc='NorthWest';
        end;
        %legend('SIMULATION','COURBE THEORIQUE','GABARIT','location',loc)
        if super
		hold on
	else 
		hold off
		vminig=[];
		vmaxig=[];
	end;
    end;
	zoom on
end;
if courbes(2)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom,' - 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
	else 
		hold off
		vminip=[];
		vmaxip=[];
	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),w/(2*pi))
			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;
	set(gcf,'userdata',v);
	zoom on
	if nouveau
		echelles;
	end;
end;
if courbes(3)
	f=get(0,'chil');
	nouveau=1;
	nom_fig=[nom,' - 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)')
	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 )')
	zoom on
end;
end;

Contact us