Code covered by the BSD License  

Highlights from
Analog Filter Design Toolbox

image thumbnail

Analog Filter Design Toolbox

by

 

27 Dec 2005 (Updated )

GUI to design and simulate active (opamp) LP and HP Bessel, Butter, Cheby, and Elliptic filters.

BuildCircuit_FindZ1P1K1(curStage)
function curStage = BuildCircuit_FindZ1P1K1(curStage)
% BuildCircuit_FindZ1P1K1 is a subfile of the AnalogFilter GUI collection
%
% BuildCircuit_FindZ1P1K1 finds the p1, z1, k1, Q1, wp1, and wz1 for a given filter stage.
% It is calculated, as the suffix "1" implies, using the actual toleranced component values.
% James C. Squire, Assistant Professor, Virginia Military Institute
% ver 1.0

% setup
schName = curStage.schName;
vfCSelect = curStage.vfCSelect;
vfRSelect = curStage.vfRSelect;
vfCCalc = curStage.vfCCalc;
vfRCalc = curStage.vfRCalc;

% find the z1, p1, k1
switch upper(schName)
    case 'SK_LP_KLE1'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        if isinf(R2), R2 = 10e22; end  % practically infinity
        if R2~=0
            pimag = sqrt(C1*(4*Ca*R2*(R1+R2)-C1*(R1+2*R2)^2))/(2*R1*R2*Ca*C1);
            p1(1) = -(R1+2*R2)/(2*R1*R2*Ca)+j*pimag;
        else
            p1(1) = (-1+sqrt(1-Ca/C1))/(Ca*R1);
        end
        p1(2) = conj(p1(1));
        k1 = 1/(R1^2*Ca*C1);
        if R2==10e22, R2 = inf; end
    case 'SK_LP_KGT1'
        Ca = vfCSelect(1);
        Ra = vfRSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        pimag = sqrt(4*R1^2*Ra^2*Ca*C1-(R1*R2*Ca-2*R1*Ra*C1)^2)/(2*R1^2*Ra*Ca*C1);
        p1(1) = -(2*C1*Ra-Ca*R2)/(2*R1*Ra*Ca*C1)+j*pimag;
        p1(2) = conj(p1(1));
        k1 = (Ra+R2)/(R1^2*Ra*Ca*C1);
    case 'SK_HP_KLE1'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [0 0];
        pimag = sqrt(4*R1*R2*Ca*(C1+Ca)-(R2*C1+2*R2*Ca)^2)/(2*R1*R2*Ca*(C1+Ca));
        p1(1) = -(C1+2*Ca)/(2*R1*Ca*(C1+Ca))+j*pimag;
        p1(2) = conj(p1(1));
        k1 = Ca/(Ca+C1);
    case 'SK_HP_KGT1'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        z1 = [0 0];
        k1 = (R3+R1)/R1;
        pimag = sqrt(4*R1*R2-(R1*(1-k1)+2*R2)^2)/(2*R1*R2*Ca);
        p1(1) = -(R1*(1-k1)+2*R2)/(2*R1*R2*Ca)+j*pimag;
        p1(2) = conj(p1(1));
    case 'MFB_LP'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        pimag = sqrt(Ca*(4*R2^2*C1-Ca*(R1+2*R2)^2))/(2*R1*R2*Ca*C1);
        p1(1) = -(R1+2*R2)/(2*R1*R2*C1)+j*pimag;
        p1(2) = conj(p1(1));    
        k1 = -1/(R1*R2*Ca*C1);
    case 'MFB_Z_LP'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        a = 4*R1^2*R3*C1*Ca*(R1+R3);
        b = (R2*R3*Ca-R1*C1*(R1+2*R3))^2;
        c = 2*R1^2*R3*Ca*C1;
        zimag = sqrt(a-b)/c;
        zreal = -(R1*C1*(R1+2*R3)-R2*R3*Ca)/(2*R1^2*R3*C1*Ca);
        z1(1) = zreal + j*zimag;
        z1(2) = conj(z1(1));
        pimag = sqrt(4*R3^2*Ca*C1-(R1*C1+2*R3*C1)^2)/(2*R1*R3*Ca*C1);
        p1(1) = -(R1+2*R3)/(2*R1*R3*Ca)+j*pimag;
        p1(2) = conj(p1(1)); 
        k1 = R1/(R1+R2);
    case 'MFB_Z_HP'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        a = 4*Ca*R1*R3*(C1+Ca)+(Ca*R2-C1*R3-2*Ca*R3)^2;
        b = 2*Ca*R1*R3*(C1+Ca);
        zimag = sqrt(a)/b;
        zreal = -(Ca*(2*R3-R2)+C1*R3)/(2*Ca*R1*R3*(C1+Ca));
        z1(1) = zreal+j*zimag;
        z1(2) = conj(z1(1));
        pimag = sqrt(4*Ca^2*R1*R3-(C1*R3+2*Ca*R3)^2)/(2*R1*R3*Ca^2);
        p1(1) = -(C1+2*Ca)/(2*Ca^2*R1)+j*pimag;
        p1(2) = conj(p1(1)); 
        k1 = R1*(Ca+C1)/(Ca*(R1+R2));
    case 'AM_LP_N'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        z1 = [];
        pimag = sqrt(4*R2^2-R1^2)/(2*R1*R2*Ca);
        p1(1) = -1/(2*R2*Ca)+j*pimag;
        p1(2) = conj(p1(1)); 
        k1 = 1/(R1*R3*Ca^2);        
    case 'AM_LP_I'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        z1 = [];
        pimag = sqrt(4*R2^2-R1^2)/(2*R1*R2*Ca);
        p1(1) = -1/(2*R2*Ca)+j*pimag;
        p1(2) = conj(p1(1)); 
        k1 = -1/(R1*R3*Ca^2);                
    case 'AM_HP'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [0 0];
        pimag = sqrt(4*R2^2-R1^2)/(2*R1*R2*Ca);
        p1(1) = -1/(2*R2*Ca)+j*pimag;
        p1(2) = conj(p1(1)); 
        k1 = -C1/Ca;             
    case 'AM_Z'
        Ca = vfCSelect(1);
        C1 = vfCCalc(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        R3 = vfRCalc(3);
        k1 = -C1/Ca;
        z1(1) = 1/(Ca*sqrt(k1*R1*R3));
        z1(2) = conj(z1(1));
        pimag = sqrt(4*R2^2-R1^2)/(2*R1*R2*Ca);
        p1(1) = -1/(2*R2*Ca)+j*pimag;
        p1(2) = conj(p1(1)); 
    case 'SO_LP_N_KLE1'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        if isinf(R2)
            p1 = -1/(R1*Ca);
        else
            p1 = -(R1+R2)/(Ca*R1*R2);
        end
        k1 = 1/(R1*Ca);
    case 'SO_LP_N_KGT1'
        Ca = vfCSelect(1);
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        p1 = -1/(Ca*R1);
        k1 = (Ra+R2)/(R1*Ra*Ca);
    case 'SO_LP_I'
        Ca = vfCSelect(1);
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [];
        p1 = -(Ra+R2)/(Ca*Ra*R2);
        k1 = -R1/(Ra*R2*Ca);
    case 'SO_HP_N_KLE1'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [0];
        p1 = -1/(Ca*(R1+R2));
        k1 = R2/(R1+R2);
    case 'SO_HP_N_KGT1'
        Ca = vfCSelect(1);
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [0];
        p1 = -1/(Ca*R1);
        k1 = 1+R2/Ra;
    case 'SO_HP_I'
        Ca = vfCSelect(1);
        R1 = vfRCalc(1);
        R2 = vfRCalc(2);
        z1 = [0];
        p1 = -1/(Ca*R1);
        k1 = -R2/R1;
    case 'ZO_N_KLE1'
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        z1 = [];
        p1 = [];
        k1 = R1/(Ra+R1);
    case 'ZO_N_KGT1'
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        z1 = [];
        p1 = [];
        k1 = 1+R1/Ra;
    case 'ZO_I'
        Ra = vfRSelect(1);
        R1 = vfRCalc(1);
        z1 = [];
        p1 = [];
        k1 = -R1/Ra;
    otherwise
        error(['unknown circuit title name ' schName ' in' mfilename])
end

% find the Q1, wp1, wz1
if length(z1)
    wz1 = abs(z1(1));
else
    wz1 = [];
end
if length(p1)
    wp1 = abs(p1(1));
    Q1 = -wp1/(2*real(p1(1)));
else
    wp1 = [];
    Q1 = [];
end

% fill up curStage with calculated values
curStage.z1 = z1;
curStage.p1 = p1;
curStage.k1 = k1;
curStage.Q1 = Q1;
curStage.wp1 = wp1;
curStage.wz1 = wz1;

Contact us