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_SelectCircuit(strCircuit, curStage, schTitle)
function strCircuit = BuildCircuit_SelectCircuit(strCircuit, curStage, schTitle)
% BuildCircuit_SelectCircuit is a subfile of the AnalogFilter GUI collection
%
% BuildCircuit_SelectCircuit recalculates strCircuit biquad with a new given circuit type.
% Because the new circuit may require a different/new/deleted final circuit gain stage,
% the entire strCircuit structure must be passed to it.
%
% James C. Squire, Assistant Professor, Virginia Military Institute
% ver 1.0


sPurpose = strCircuit.sPurpose; % LP, HP, or Notch
k = abs(strCircuit.vStage(curStage).k);
switch sPurpose
    case 'LP'
        switch schTitle
            case 'Sallen-Key'
                % kDC = k / pp* for LP or k otherwise - important because SK uses a different 
                % configuration for kDC <=1 and >1 
                kDC = abs(k/(abs(strCircuit.vStage(curStage).p(1))^2));
                if abs(kDC-1) < 0.00001 % make it exact
                    kDC = 1;
                end
                if kDC <= 1
                    schName = 'SK_LP_kLE1';
                else
                    schName = 'SK_LP_kGT1';
                end
            case 'Multiple Feedback'
                schName = 'MFB_LP';
            case 'Ackerberg-Mossberg (+)'
                schName = 'AM_LP_N';
            case 'Ackerberg-Mossberg (-)'
                schName = 'AM_LP_I';
            otherwise, error(['Unrecognized schTitle ' schTitle])
        end
    case 'HP'
        switch schTitle
            case 'Sallen-Key'
                if k<=1
                    schName = 'SK_HP_kLE1';
                else
                    schName = 'SK_HP_kGT1';
                end
            case 'Ackerberg-Mossberg'
                schName = 'AM_HP';
            otherwise, error(['Unrecognized schTitle ' schTitle])
        end
    case 'Notch'
        switch schTitle
            case 'Multiple Feedback'
                if  isempty(strCircuit.vStage(curStage).z) 
                    error('Not a Notch if no zeros present')
                end
                z=strCircuit.vStage(curStage).z(1);
                p=strCircuit.vStage(curStage).p(1);
                if abs(z) > abs(p) %LP
                    schName = 'MFB_Z_LP';
                else %HP
                    schName = 'MFB_Z_HP';
                end
            case 'Ackerberg-Mossberg'
                schName = 'AM_Z';
            otherwise, error(['Unrecognized schTitle ' schTitle])
        end
    otherwise error(['Unrecognized sPurpose ' sPurpose] )
end

% save the new schName, schTitle in strCircuit
strCircuit.vStage(curStage).schName = schName;
strCircuit.vStage(curStage).schTitle = schTitle;

% update the components in this stage
nCTol = strCircuit.nCTol;
nRTol = strCircuit.nRTol;
strCircuit.vStage(curStage) = BuildCircuit_UpdateComponents(strCircuit.vStage(curStage),nRTol,nCTol);
strCircuit = BuildCircuit_LastStage(strCircuit); % possible gain stage has changed

Contact us