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_bas(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_bas(type,Fp,Fa,Attmax,Attmin,choix,valeur)

selectivite=Fp/Fa;
wp=2*pi*Fp;
wa=2*pi*Fa;
wpnorm=10^(ceil(log10(wa)));
WP=wp/wpnorm;
WA=wa/wpnorm;
nb_etage=0;
switch choix
case 'R'
    R0=valeur;
    C0=1/(wp*R0);
case 'C'
    C0=valeur;
    R0=1/(wp*C0);
end;    
switch type
    case 'butterworth'
        [n WN]=buttord(WP,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);
        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=[];
        for b=1:2:long-1
                [num den]=zp2tf(z,pordonne(b:b+1),1);
                [numfin denfin]=lp2lp(num,den,wp);
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                C1et=2/(R0*denfin(2));
                C2et=1/(R0^2*C1et*denfin(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                nb_etage=nb_etage+1;
                R1=[R1;R0];
                R2=[R2;R0];
                RP=[RP;1e12];
         end;
         if long/2~=floor(long/2)
                [num den]=zp2tf(z,pordonne(long),1);
                [numfin denfin]=lp2lp(num,den,wp);
                denfin=[0,denfin];
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                C1et=NaN;
                C2et=1/(R0*denfin(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                 nb_etage=nb_etage+1;
                 R1=[R1;R0];
                 R2=[R2;R0];
                 RP=[RP;1e12];
            end;                
        
                
    case 'chebychef'
        [n WN]=cheb1ord(WP,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);
        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=[];
        gain_global=k/abs(prod(p));
        exposant=floor(long/2);
        gain_etage=gain_global^(1/exposant);
        for b=1:2:long-1
                k_etage=gain_etage*abs(pordonne(b))^2;
                [num den]=zp2tf(z,pordonne(b:b+1),k_etage);
                [numfin denfin]=lp2lp(num,den,wp);
                A1=num(end)/den(end);
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                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*denfin(2));
                C2et=1/(A1*R0^2*C1et*denfin(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                 nb_etage=nb_etage+1;
                 R1=[R1;R0];
                R2=[R2;R0];
         end;
         if long/2~=floor(long/2)
                [num den]=zp2tf(z,pordonne(long),abs(pordonne(long)));
                [numfin denfin]=lp2lp(num,den,wp);
                denfin=[0,denfin];
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                C1et=NaN;
                C2et=1/(R0*denfin(3));
                C1=[C1;C1et];
                C2=[C2;C2et];
                 nb_etage=nb_etage+1;
                 R1=[R1;R0];
                R2=[R2;R0];
                RP=[RP;1e12];
            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; 
fct=tf(NUM,DEN,'variable','p');
CP=inf*ones(size(RP));

Contact us