from CPW Low Pass Filter Design by Miriyala Aravind
CPW Low Pass Filter Design using Matlab

CpwFilter.m
%Roh-Maximum Characteristic Impedance that can be achieved using CPW filter
%Rol-Minimum Characteristic Impedance that can be achieved using CPW filter
%Ro-Impedance of filter
%fc-Cut-off frequency of lowpass filter
%g[n]-Filter coefficients
%Actual[n]-Actual L,C,R values
%L=g[k]*Ro/2*pi*fc
%C=g[k]/Ro*2*pi*fc
%n-No. of filter coefficients
%l[k]-Lengths of elements
%A[k]-Angles-beta*l 
%epso-Dielectric constant of air
%muo-Permeablility of air
%epsr-Dielectric constant of the material
%epseff-Effective Dielectric constant
%lambdag-Wavelength in the dielectric
%ratiol-b/a for Rol
%ratioh-b/a for Roh
%L-Insertion loss in dB at frequency f
%Lm-Ripple magnitude in dB
%W[k]-Width of Tx. line
%D-Distance between two ground planes
repeat='y';
while repeat=='y'
    clc
    clear
    %Constants
    epso=8.854*power(10,-12);
    muo=4*pi*power(10,-7);
    Rol=100;
    Roh=750;
    Ro=300;
    choice=menu('Click on your choice','Chebychev filter','Butterworth filter','Plot between Characteristic impedance and b/a','Plot between Insertion loss and n');
    if isequal(choice,1)
        choice1=1;
    elseif isequal(choice,2)
        choice1=1;
    elseif isequal(choice,3)
        choice1=2;
    elseif isequal(choice,4)
        choice1=3;
    end
    switch (choice1)
%Normalized values for Butterworth filter
        case 1
            if isequal(choice,2)
                fc=input('Enter the Cut-off frequency in Giga Hertz(GHz)    :');
                L=input('Required Insertion loss in dB    :');
                f=input('At frequency in Giga Hertz(GHz)    :');
                n=0.5*(log(power(10,L/10)-1)/log(f/fc));
                n=ceil(n);
                if isequal(rem(n,2),0)
                    n=n+1;
                end
                g(1)=1;
                for i=2:n+1
                    g(i)=2*sin((2*(i-1)-1)*pi/(2*n));
                end
                g(n+2)=1;
%Normalized values for Chebychev filter
%Temporary variables-a(i),b(i),gamma,beta
            else
                fc=input('Enter the Cut-off frequency in Giga Hertz(GHz)    :');
                L=input('Required Insertion loss in dB    :');
                f=input('At frequency in Giga Hertz(GHz)    :');
                Lm=input('Ripple magnitude in dB    :');
                if (f/fc)<1
                    n=acos(sqrt((power(10,L/10)-1)/(power(10,Lm/10)-1)))/acos(f/fc);
                else
                    n=acosh(sqrt((power(10,L/10)-1)/(power(10,Lm/10)-1)))/acosh(f/fc);
                end
                n=ceil(n);
                if isequal(rem(n,2),0)
                    n=n+1;
                end
                g(1)=1;
                g(n+2)=1;
                beta=log(coth(Lm/17.37));
                gamma=sinh(beta/(2*n));
                for i=2:1:n+1
                    a(i)=sin((2*i-3)*pi/(2*n));
                    b(i)=power(gamma,2)+power(sin((i-1)*pi/n),2);
                end
                g(2)=2*a(2)/gamma;
                for i=3:1:n+1
                    g(i)=4*a(i-1)*a(i)/(b(i-1)*g(i-1));
                end
            end
            epsr=input('Enter the di-electric constant of the material    :');
%Calculation for normalized values is over
            epseff=(epsr+1)/2;
            lambdag=3*power(10,8)/(fc*sqrt(epseff)*power(10,9));
            Actual(1)=g(1)*Ro;
            Actual(n+2)=g(n+2)*Ro;
            for i=2:2:n+1
                Actual(i)=g(i)*power(10,12)/(Ro*2*pi*fc);   % in pico farad
                l(i)=asin(g(i)*Rol/Ro)*lambdag*1000/(2*pi); % in mm
                A(i)=asin(g(i)*Rol/Ro)*180/pi;
            end
            for i=3:2:n+1
                Actual(i)=g(i)*Ro*power(10,9)/(2*pi*fc);    % in nano henry
                l(i)=asin(g(i)*Ro/Roh)*lambdag*1000/(2*pi); % in mm
                A(i)=asin(g(i)*Ro/Roh)*180/pi;
            end
            ratiol=power(power(0.25*(exp(pi*Rol*sqrt(2*epso*(epsr+1)/muo))-(1+pi*Rol*sqrt(2*epso*(epsr+1)/muo))),-0.0068*Rol+2.5986)+power(1+8*exp(-1*pi*sqrt(muo/(8*epso*(epsr+1)))/Rol),-0.0068*Rol+2.5986),1/(-0.0068*Rol+2.5986));
            ratioh=power(power(0.25*(exp(pi*Roh*sqrt(2*epso*(epsr+1)/muo))-(1+pi*Roh*sqrt(2*epso*(epsr+1)/muo))),-0.0068*Roh+2.5986)+power(1+8*exp(-1*pi*sqrt(muo/(8*epso*(epsr+1)))/Roh),-0.0068*Roh+2.5986),1/(-0.0068*Roh+2.5986));
%Distance between two ground planes is constant
            D=lambdag;
            Tlength=0;
            for i=2:n+1
                if rem(i,2)==0
                    W(i)=D/ratiol;
                else
                    W(i)=D/ratioh;
                end
                Tlength=Tlength+l(i);
            end
            if Tlength>100
                hscale=150;
                vscale=3;
            end
            hscale=100;
            vscale=2;
            display('Vertical Scale');display(vscale);
            display('Horizantal Scale');display(hscale);
%Drawing the layout-Scaling widths by vscale,lengths by hscale
            temp=0.1;
            handle=annotation('rectangle',[0.1 0.5+vscale*D/2 Tlength/hscale 0.2]);
            set(handle,'Facecolor',[0 0 0]);
            handle=annotation('rectangle',[0.1 0.3-vscale*D/2 Tlength/hscale 0.2]);
            set(handle,'Facecolor',[0 0 0]);
            for i=2:n+1
                handle=annotation('rectangle',[temp 0.5-vscale*W(i)/2 l(i)/hscale vscale*W(i)]);
                if rem(i,2)==0
                    set(handle,'FaceColor',[1 0 1]);
                else
                    set(handle,'FaceColor',[0 1 1]);
                end
                temp=temp+l(i)/hscale;
            end
%Plotting the graph between Z0 and b/a
        case 2
            epsr1=input('Enter the di-electric constant of the material(epsr1)    :');
            epsr2=input('Enter the di-electric constant of the material(epsr2)    :');
            figure;
            hold on;
            Z0=50:10:350;
            for i=1:31
                epsr=epsr1;
                ratio(i)=power(power(0.25*(exp(pi*Z0(i)*sqrt(2*epso*(epsr+1)/muo))-(1+pi*Z0(i)*sqrt(2*epso*(epsr+1)/muo))),-0.0068*Z0(i)+2.5986)+power(1+8*exp(-1*pi*sqrt(muo/(8*epso*(epsr+1)))/Z0(i)),-0.0068*Z0(i)+2.5986),1/(-0.0068*Z0(i)+2.5986));
                ratio(i)=1/ratio(i);
                epsr=epsr2;
                ration(i)=power(power(0.25*(exp(pi*Z0(i)*sqrt(2*epso*(epsr+1)/muo))-(1+pi*Z0(i)*sqrt(2*epso*(epsr+1)/muo))),-0.0068*Z0(i)+2.5986)+power(1+8*exp(-1*pi*sqrt(muo/(8*epso*(epsr+1)))/Z0(i)),-0.0068*Z0(i)+2.5986),1/(-0.0068*Z0(i)+2.5986));
                ration(i)=1/ration(i);
            end
            plot(Z0,ratio,'r',Z0,ration,'m');
            legend('epsr1','epsr2');
            xlabel('Characteristic Impedance');
            ylabel('a/b');
        case 3
            option=input('Enter the filter type-Chebychev(C)/Butterworth(B)','s');
            figure;
            hold on;
            relf=logspace(-1,0.25,31);
            if option=='B'
                for i=1:31
                    Loss1(i)=10*log10(1+power(relf(i),2*3));
                    Loss2(i)=10*log10(1+power(relf(i),2*5));                    
                    Loss3(i)=10*log10(1+power(relf(i),2*7));
                    Loss4(i)=10*log10(1+power(relf(i),2*9));
                end
            else
                for i=1:31
                    if relf<1
                        Loss1(i)=10*log10(1+(power(10,0.05)-1)*power(cos(3*acos(relf(i))),2));
                    else
                        Loss1(i)=10*log10(1+(power(10,0.05)-1)*power(cosh(3*acosh(relf(i))),2));
                    end
                    if relf<1
                        Loss2(i)=10*log10(1+(power(10,0.05)-1)*power(cos(5*acos(relf(i))),2));
                    else
                        Loss2(i)=10*log10(1+(power(10,0.05)-1)*power(cosh(5*acosh(relf(i))),2));
                    end
                    if relf<1
                        Loss3(i)=10*log10(1+(power(10,0.05)-1)*power(cos(7*acos(relf(i))),2));
                    else
                        Loss3(i)=10*log10(1+(power(10,0.05)-1)*power(cosh(7*acosh(relf(i))),2));
                    end
                    if relf<1
                        Loss4(i)=10*log10(1+(power(10,0.05)-1)*power(cos(9*acos(relf(i))),2));
                    else
                        Loss4(i)=10*log10(1+(power(10,0.05)-1)*power(cosh(9*acosh(relf(i))),2));
                    end
                end
            end
            semilogx (relf,Loss1,'r',relf,Loss2,'m',relf,Loss3,'b',relf,Loss4,'g');
            xlabel('Relative frequecy');ylabel('Attenuation in dB');
            legend('n=3','n=5','n=7','n=9');
    end
    repeat=input('Do you want to repeat the calculation(y/n)    :','s');
end

Contact us at files@mathworks.com