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

selectivite=Fa/Fp;
wp=2*pi*Fp;
wa=2*pi*Fa;
wp_proto=wp;
wa_proto=wp_proto/selectivite;
wpnorm=10^(ceil(log10(wp_proto)));
WP=wp_proto/wpnorm;
WA=wa_proto/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);
        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=[];
        CP=[];
        for b=1:2:long-1
                [num den]=zp2tf(z,pordonne(b:b+1),1);
                %num=num*den(end);
                [numfin denfin]=lp2hp(num,den,wp);
                denmax=max(denfin);
                knum=find(abs(numfin)<=1e-10*denmax);
                numfin(knum)=0;
                 numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                R2et=2/(C0*denfin(2));
                R1et=1/(R2et*denfin(3)*C0^2);
                C1=[C1;C0];
                C2=[C2;C0];
                nb_etage=nb_etage+1;
                R1=[R1;R1et];
                R2=[R2;R2et];
                CP=[CP;0];
         end;
         if long/2~=floor(long/2)
                [num den]=zp2tf(z,pordonne(long),1);
                %num=num*den(end);
                [numfin denfin]=lp2hp(num,den,wp);
                denmax=max(denfin);
                knum=find(abs(numfin)<=1e-10*denmax);
                numfin(knum)=0;
                denfin=[0,denfin];
                numfin=[0,numfin];
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                R1et=NaN;
                R2et=1/(C0*denfin(3));
                C1=[C1;C0];
                C2=[C2;C0];
                 nb_etage=nb_etage+1;
                 R1=[R1;R1et];
                 R2=[R2;R2et];
                 CP=[CP;0];
            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=[];
        CP=[];
         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]=lp2hp(num,den,wp);
                numfin(2:end)=0;
                 A1=numfin(1)/denfin(1);
                numfinal=[numfinal;numfin];
                denfinal=[denfinal;denfin];
                 if abs(A1-1)<=eps
                    CP=[CP;0];
                else
                    C_Cp=(1-A1)/A1;
                    CP=[CP;C0*C_Cp];
                end;
                R2et=(1+A1)/(C0*denfin(2));
                R1et=A1/(R2et*denfin(3)*C0^2);
                C1=[C1;C0];
                C2=[C2;C0];
                nb_etage=nb_etage+1;
                R1=[R1;R1et];
                R2=[R2;R2et];
         end;
         if long/2~=floor(long/2)
                [num den]=zp2tf(z,pordonne(long),abs(pordonne(long)))
                [numfin denfin]=lp2hp(num,den,wp)
               denfin=[0,denfin];
               numfin=[0,numfin];
                numfin(3)=0;
                numfinal=[numfinal;numfin]
                denfinal=[denfinal;denfin]
                R1et=NaN;
                R2et=1/(C0*denfin(3));
                C1=[C1;C0];
                C2=[C2;C0];
                 nb_etage=nb_etage+1;
                 R1=[R1;R1et];
                 R2=[R2;R2et];
                 CP=[CP;0];
            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');
RP=inf*ones(size(CP));

Contact us