% vcvs_2_4.m - complex numbers to compute gain and phase for % second-order and fourth-order VCVS LP filter % HJSIII - 07.10.17 clear clf % cutoff frequency [Hz] fc = 1 / (2*pi*R*C) % capacitor [Farads] fc = 15; C = 0.1E-6; C1 = C; C2 = C; % single-stage second-order passband gain % K fn % Butterworth 1.586 1 % Bessel 1.268 1.272 % 2dB Chebyshev 2.114 0.907 K = 1.586; fn = 1; R = 1 / (2*pi*fc*C*fn); R1 = R; R2 = R; % two-stage fourth-order passband gains and normalizing factors % KA fnA KB fnB % Butterworth 1.152 1 2.235 1 % Bessel 1.084 1.432 1.759 1.606 % 2dB Chebyshev 1.924 0.471 2.782 0.964 KA = 1.152; fnA = 1; KB = 2.235; fnB = 1; RA = 1 / (2*pi*fc*C*fnA); R1A = R; R2A = R; RB = 1 / (2*pi*fc*C*fnB); R1B = R; R2B = R; % use 0.01 Hz <= f <= 1 MHz lf = -2:0.01:6; f = 10 .^ lf; % capacitor impedance ZC1 = -j ./ ( 2 * pi * f * C1 ); ZC2 = -j ./ ( 2 * pi * f * C2 ); % gain G = K.*ZC1.*ZC2 ./ ( ( R1+ZC1).*( R2+ZC2) + R1*(ZC1- K*ZC2) ); GA = KA.*ZC1.*ZC2 ./ ( (R1A+ZC1).*(R2A+ZC2) + R1A*(ZC1-KA*ZC2) ); GB = KB.*ZC1.*ZC2 ./ ( (R1B+ZC1).*(R2B+ZC2) + R1B*(ZC1-KB*ZC2) ); G4 = GA .* GB; % save log of gain and phase in degrees dB = 20 * log10( abs( G ) ); dB4 = 20 * log10( abs( G4 ) ); phi = angle( G ) * 180 / pi; phi4 = unwrap( angle( G4 ) ) * 180 / pi; % plot subplot(2,1,1) plot( lf,dB,'-', lf,dB4,'--' ) axis( [ -2 6 -160 20 ] ) title('VCVS 100 Hz LP filters') xlabel('log f') ylabel('Gain (dB)') legend( 'Second-order', 'Fourth-order' ) subplot(2,1,2) plot( lf,phi,'-' , lf,phi4,'--' ) axis( [ -2 6 -360 90 ] ) xlabel('log f') ylabel('Phase (deg)') legend( 'Second-order', 'Fourth-order' )