Contents

Low Pass

clear
s = tf('s');
ww=.01:1:1e5;
wc=25000;
% Highest piano key at 4186.01 Hz = 2.63e4 rps

% I'll be implementing this whole thing using butterworth for now.
% Hopefully, by the time I get to it again, I'll be good enough to use
% sharper filters.

[z p k]=buttap(4);%Get info for a 4th order butterworth filter
[num den]=lp2lp(k*poly(z),poly(p),wc);%Implement filter
LP=tf(num,den);P=pole(LP);Z=zero(LP);
LP1=tf(1e9,poly(P(1:2)));
LP2=tf(4e8,poly(P(3:4)));

K1=1.6;Q1=1.3089;
BQ1=(K1)/(s^2/wc^2+s/(wc*Q1)+1);
K2=.64;Q2=.54124;
BQ2=(K2)/(s^2/wc^2+s/(wc*Q2)+1);

[LPmag LPphase]=bode(LP,ww);
[LP1mag LP1phase]=bode(LP1,ww);
[LP2mag LP2phase]=bode(LP2,ww);
[BQ1mag BQ1phase]=bode(BQ1,ww);
[BQ2mag BQ2phase]=bode(BQ2,ww);

figure(1);clf;
subplot(211),pzplot(LP)
legend('Desired pzplot','Location','East')
subplot(212),pzplot(LP1,LP2)
legend('Biquad 1','Biquad 2','Location','East')

figure(2);clf;
subplot(211),plot(ww,LP1mag(:,:).*LP2mag(:,:),'b',ww,LPmag(:,:),'k:')
legend('Designed response','Desired response')
subplot(212),plot(ww,BQ1mag(:,:),'b',ww,BQ2mag(:,:),'r',ww,LP1mag(:,:),'k:',ww,LP2mag(:,:),'k:')
legend('Biquad 1 - designed','Biquad 2 - designed')

Designing the Sallen-Key filters to implement my low-pass

clear
s = tf('s');
ww=.01:1:1e5;
% So. The important parts of my filters are the Q factors and the gains.
% I'd like to match these in order to replicate my theoretical desing in a
% circuit design.
wc=25000;
K1=1.6;Q1=1.3089;
BQ1=(K1)/(s^2/wc^2+s/(wc*Q1)+1);
K2=.64;Q2=.54124;
BQ2=(K2)/(s^2/wc^2+s/(wc*Q2)+1);

C1=56e-9;C2=8.2e-9;R1=1.2e3;R2=3e3;
C1=39e-9;
%Somewhere between 39nF and 47nF everything goes crazy and rails. Also,
%some weird high frequency appears to be added in. I'd say it's because of
%the high part of the freq response except the input has amplitude less
%than 1 and the magnitude of the response is never greater than 2.2ish.
%Then again, the magnitude of my new filter with smaller cap shouldn't go
%above 4, but it gets near 7... Even so. It would need to get to 10 in
%order to cause issues. I dunno. It's lame.
Circ1=K1/(R1*R2*C1*C2*s^2+(R1*C2+(1-K1)*R1*C1)*s+1);

C1=5.6e-9;C2=5.6e-9;R1=10e3;R2=5.1e3;
Circ2=K2/(R1*R2*C1*C2*s^2+(R1*C2+(1-K2)*R1*C1)*s+1);

[BQ1mag BQ1phase]=bode(BQ1,ww);
[BQ2mag BQ2phase]=bode(BQ2,ww);
[Circ1mag Circ1phase]=bode(Circ1,ww);
[Circ2mag Circ2phase]=bode(Circ2,ww);

%The plot below shows what the change I was forced to make should do to my
%frequency response.
figure(3);clf;
subplot(211),plot(ww,Circ1mag(:,:).*Circ2mag(:,:),ww,BQ1mag(:,:).*BQ2mag(:,:),'k:')
subplot(212),plot(ww,Circ1mag(:,:),'b',ww,Circ2mag(:,:),'r',ww,BQ1mag(:,:),'k:',ww,BQ2mag(:,:),'k:')

Results

%It's been far too long since this lab and it seems like the motivation
%needed to go retake data will not be achieved. As a result, I'll say what
%I remember. The vague qualitative response was correct except that the
%actual implementation had a good deal more peaking than my theoretical
%version. The issue with the capacitor choice causing an insane amount of
%noise was not resolved. It was suggested that I check component values,
%but I did not do so. I apologize for handing in shoddy work, but I don't
%see much more benefit to my learning in improving this lab report.