% vcvs_tol.m - effects of component tolerances in second-order % VCVS LP filter - Fig 5.16, p. 274 in H&H % HJSIII - 98.07.09 clear clf % component tolerance - 10% pct = 0.1; % cutoff frequency (Hz) fc = 1 / (2*pi*R*C) % capacitor (Farads) fc = 15; C1C2_des = 0.1E-6; % single-stage second-order passband gain % K fn % Butterworth 1.586 1 % Bessel 1.268 1.272 % 2dB Chebyshev 2.114 0.907 K_des = 1.586; R_des = 10000; RKm1_des = (K_des - 1) * R_des; fn = 1; R1R2_des = 1 / (2*pi*fc*C1C2_des*fn); % use 0.01 Hz <= f <= 1 MHz % -2 <= log(f) <= 6 lf = -2:0.01:6; f = 10 .^ lf; % initialize max/min npts = 51; dB_max = -1000 * ones( size(f) ); dB_min = 1000 * ones( size(f) ); phi_max = -1000 * ones( size(f) ); phi_min = 1000 * ones( size(f) ); % repeat 1000 times nrep = 1000; for irep = 1:nrep, irep if irep == nrep, pct = 0; end % add random tolerance to components R = R_des * ( 1 + pct*(2*rand-1) ); RKm1 = RKm1_des * ( 1 + pct*(2*rand-1) ); K = 1 + (RKm1 / R); R1 = R1R2_des * ( 1 + pct*(2*rand-1) ); R2 = R1R2_des * ( 1 + pct*(2*rand-1) ); C1 = C1C2_des * ( 1 + pct*(2*rand-1) ); C2 = C1C2_des * ( 1 + pct*(2*rand-1) ); % 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) ); % gain in dB and phase in degrees dB = 20 * log10( abs( G ) ); phi = angle( G ) * 180 / pi; % find max/min dB_max = max( dB_max, dB ); dB_min = min( dB_min, dB ); phi_max = max( phi_max, phi ); phi_min = min( phi_min, phi ); % next irep end % set up plots subplot(2,1,1) Kplot = 20*log10(K)*ones( size(f) ); plot( lf,dB, lf,dB_max, lf,dB_min, lf,Kplot,'--' ) axis( [ -1 3 -40 10 ] ) title('VCVS LP filter - 10% component variation') xlabel('log f') ylabel('Gain (dB)') subplot(2,1,2) plot( lf,phi, lf,phi_max, lf,phi_min ) axis( [ -1 3 -190 10 ] ) xlabel('log f') ylabel('Phase (deg)') hold on