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

[ordre,nb_etage,numfinal,denfinal,NUM,DEN,C1,C2,R1,R2,RP,CP,R0,C0,fct]=passe_bande(type,Fp,Fa,Attmax,Attmin,choix,valeur)
function [ordre,nb_etage,numfinal,denfinal,NUM,DEN,C1,C2,R1,R2,RP,CP,R0,C0,fct]=passe_bande(type,Fp,Fa,Attmax,Attmin,choix,valeur)

rauch=false;
selectivite=(Fp(2)-Fp(1))/(Fa(2)-Fa(1));
wp=2*pi*Fp;
wa=2*pi*Fa;
w0=sqrt(wp(1)*wp(2));
w0_proto=w0;
wa_proto=w0_proto/selectivite;
B=wp(2)-wp(1);
wpnorm=10^(ceil(log10(wa(2))));
W0=w0_proto/wpnorm;
WA=wa_proto/wpnorm;
Bnorm=B/wpnorm;
nb_etage=0;
switch choix
case 'R'
    R0=valeur;
    C0=1/(w0*R0);
case 'C'
    C0=valeur;
    R0=1/(w0*C0);
end;    
switch type
    case 'butterworth'
        [n WN]=buttord(W0,WA,Attmax,Attmin,'s');
        ordre=n;
        [z,p,k]=buttap(n);
        kreel=find(abs(imag(p))<=1e-10*abs(real(p)));
        p(kreel)=real(p(kreel));
        preel=p(kreel);
         kim=find(abs(real(p))<=1e-10*abs(imag(p)));
        p(kim)=imag(p(kim));
        preel=p(kreel);
        long=length(p);
        pordonne=[];
        for b=1:1:long
            if imag(p(b))>0
                pordonne=[pordonne;p(b);conj(p(b))];
            end;
        end;
        pordonne=[pordonne;preel];
        long=length(pordonne);
        numfinal=[];
        denfinal=[];
        C1=[];
        C2=[];
        R1=[];
        R2=[];
        RP=[];
        CP=[];
        for b=1:2:long-1
                [num den]=zp2tf(z,pordonne(b:b+1),1);
                [numfin denfin]=lp2bp(num,den,w0,B);
                numfin(2:end)=0;
                [zpb,ppb,kpb]=tf2zp(numfin,denfin);
                petit=min(find(abs(ppb)==min(abs(ppb))));
                grand=max(find(abs(ppb)==max(abs(ppb))));
                ppl=ppb(grand-1:grand);
                pph=ppb(petit:petit+1);
                kpl=sqrt(kpb)*abs(ppb(grand));
                [npl,dpl]=zp2tf([],ppl,kpl);
                numfinal=[numfinal;npl];
                denfinal=[denfinal;dpl];
                A1=npl(end)/dpl(end);
                 if abs(A1-1)<=eps
                    RP=[RP;1e12];
                else
                    R_Rp=(1-A1)/A1;
                    RP=[RP;R0/R_Rp];
                end;
                C1et=(1+A1)/(A1*R0*dpl(2));
                C2et=1/(A1*R0^2*C1et*dpl(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                CP=[CP;0];
                 nb_etage=nb_etage+1;
                 R1=[R1;R0];
                R2=[R2;R0];
                kph=sqrt(kpb)/abs(ppb(grand));
                 [nph,dph]=zp2tf([0;0],pph,kph);
                numfinal=[numfinal;nph];
                denfinal=[denfinal;dph];
               A1=nph(1)/dph(1);
                if abs(A1-1)<=eps
                    CP=[CP;0];
                else
                    C_Cp=(1-A1)/A1;
                    CP=[CP;C0*C_Cp];
                end;
                R2et=(1+A1)/(C0*dph(2));
                R1et=A1/(R2et*dph(3)*C0^2);
                C1=[C1;C0];
                C2=[C2;C0];
                nb_etage=nb_etage+1;
                R1=[R1;R1et];
                R2=[R2;R2et];
                RP=[RP;1e12];
         end;
         if long/2~=floor(long/2)
                rauch=true;
                [num den]=zp2tf(z,pordonne(long),1);               
                [numfin denfin]=lp2bp(num,den,w0,B);
                [zpb,ppb,kpb]=tf2zp(numfin,denfin);
                zero=[0];
                [numfin denfin]=zp2tf(zero,ppb,kpb);
                numfin(1)=0;
                numfin(end)=0;
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                dw=denfin(2);
                w0=sqrt(denfin(3));
                A1=numfin(2)/dw;
                Q=w0/dw;
                if Q^2>A1
                    C1=[C1;C0];
                    C2=[C2;C0];
                    r3=2/(dw*C0);
                    r1=1/(dw*C0*A1);
                    r2_1=w0^2*r3*C0^2-C0*dw*A1;
                    R1=[R1;r1];
                    R2=[R2;1/r2_1];
                    RP=[RP;r3];
                    CP=[CP;NaN];
                else
                    R1=[R1;R0];
                    R2=[R2;R0];
                    c1=1/(R0*dw*A1);
                    c2=dw/(w0^2*R0)-1/(R0*A1*dw);
                    r3=2/(R0*c1*c2*w0^2);
                    C1=[C1;c1];
                    C2=[C2;c2];
                    RP=[RP;r3];
                    CP=[CP;NaN];
                end
                 nb_etage=nb_etage+1;   
            end;                
        
                
    case 'chebychef'
        [n WN]=cheb1ord(W0,WA,Attmax,Attmin,'s');
        ordre=n;
        [z,p,k]=cheb1ap(n,Attmax);
        kreel=find(abs(imag(p))<=1e-10*abs(real(p)));
        p(kreel)=real(p(kreel));
        preel=p(kreel);
         kim=find(abs(real(p))<=1e-10*abs(imag(p)));
        p(kim)=imag(p(kim));
        preel=p(kreel);
        long=length(p);
        pordonne=[];
        for b=1:1:long
            if imag(p(b))>0
                pordonne=[pordonne;p(b);conj(p(b))];
            end;
        end;
        pordonne=[pordonne;preel];
        long=length(pordonne);
        numfinal=[];
        denfinal=[];
        C1=[];
        C2=[];
        R1=[];
        R2=[];
        RP=[];
        CP=[];
        exposant=floor(long/2);
        gain_etage=k^(1/exposant);
        for b=1:2:long-1
                [num den]=zp2tf([],pordonne(b:b+1),gain_etage);
                [numfin denfin]=lp2bp(num,den,w0,B);
                numfin(2:end)=0;
                [zpb,ppb,kpb]=tf2zp(numfin,denfin);
                petit=min(find(abs(ppb)==min(abs(ppb))));
                grand=max(find(abs(ppb)==max(abs(ppb))));
                ppl=ppb(grand-1:grand);
                pph=ppb(petit:petit+1);
                kpl=sqrt(kpb)*abs(ppb(grand));
                [npl,dpl]=zp2tf([],ppl,kpl);
                numfinal=[numfinal;npl];
                denfinal=[denfinal;dpl];
                A1=npl(end)/dpl(end);
                 if abs(A1-1)<=eps
                    RP=[RP;1e12];
                else
                    R_Rp=(1-A1)/A1;
                    RP=[RP;R0/R_Rp];
                end;
                C1et=(1+A1)/(A1*R0*dpl(2));
                C2et=1/(A1*R0^2*C1et*dpl(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                CP=[CP;0];
                 nb_etage=nb_etage+1;
                 R1=[R1;R0];
                R2=[R2;R0];
                kph=sqrt(kpb)/abs(ppb(grand));
                 [nph,dph]=zp2tf([0;0],pph,kph);
                numfinal=[numfinal;nph];
                denfinal=[denfinal;dph];
               A1=nph(1)/dph(1);
                if abs(A1-1)<=eps
                    CP=[CP;0];
                else
                    C_Cp=(1-A1)/A1;
                    CP=[CP;C0*C_Cp];
                end;
                R2et=(1+A1)/(C0*dph(2));
                R1et=A1/(R2et*dph(3)*C0^2);
                C1=[C1;C0];
                C2=[C2;C0];
                nb_etage=nb_etage+1;
                R1=[R1;R1et];
                R2=[R2;R2et];
                RP=[RP;1e12];
         end;
         if long/2~=floor(long/2)
                rauch=true;
                %k_etage=gain_etage*abs(pordonne(end));
                k_etage=1;
                [num den]=zp2tf(z,pordonne(long),k_etage);               
                [numfin denfin]=lp2bp(num,den,w0,B);
                [zpb,ppb,kpb]=tf2zp(numfin,denfin);
                zero=[0];
                [numfin denfin]=zp2tf(zero,ppb,kpb);
                numfin(1)=0;
                numfin(end)=0;
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                dw=denfin(2);
                w0=sqrt(denfin(3));
                A1=numfin(2)/dw;
                Q=w0/dw;
                if Q^2>A1
                    C1=[C1;C0];
                    C2=[C2;C0];
                    r3=2/(dw*C0);
                    r1=1/(dw*C0*A1);
                    r2_1=w0^2*r3*C0^2-C0*dw*A1;
                    R1=[R1;r1];
                    R2=[R2;1/r2_1];
                    RP=[RP;r3];
                    CP=[CP;NaN];
                else
                    R1=[R1;R0];
                    R2=[R2;R0];
                    c1=1/(R0*dw*A1);
                    c2=dw/(w0^2*R0)-1/(R0*A1*dw);
                    r3=2/(R0*c1*c2*w0^2);
                    C1=[C1;c1];
                    C2=[C2;c2];
                    RP=[RP;r3];
                    CP=[CP;NaN];
                end
                nb_etage=nb_etage+1;    
            end;    
end;            
NUM=[1];
DEN=[1];
[ligne,col]=size(numfinal);
for b=1:1:ligne
    NUM=conv(NUM,numfinal(b,:));
end;
[ligne,col]=size(denfinal);
for b=1:1:ligne
    DEN=conv(DEN,denfinal(b,:));
end;
while DEN(1)==0
    DEN=DEN(2:end);
end;
while NUM(1)==0
    NUM=NUM(2:end);
end; 
if rauch
    NUM=-NUM;
end;
fct=tf(NUM,DEN,'variable','p');

Contact us