Multiple filters without built in functions

3 views (last 30 days)
Lee
Lee on 2 Oct 2016
Edited: David Goodmanson on 4 Oct 2016
Hey everyone!
I cannot figure out why I'm not able to get the amplitude reponse I expect from my code. In this code I'm running one script for project that should build a plot for a Lowpass Filter, Two pole Lowpass Filter, and a Zero pole. This is for a Physics class so I don't necessarily need to know anything about using transfer functions. We're just using Labview Elvis Board during lab, and having to plot our Measured data vs. Theory data in Matlab.
The Issue You'll notice if you plot this that the Y axis should be values from 0 to -60 (about) for figure 1, and from 0 to -180 (about) for the phase. The fisrt two plots are generic Lowpass filters using theory data for my resistor and capacitor. I'm certain If these plot correctly, the rest of my plots will be okay.
Here is the code. I'm pretty certain i'm not converting something correctly but i've been looking at this for a few hours and i've come for help! It's pretty standard code. I've also included part of our experimental data so you can see the difference
R1 = 1070.2; %kOhms
R2 = 1077.4; %kOhms
RAlt = 682.4; %Ohms
C1 = .0000000003308; %uF
C2 = .0000000003322 ;%uF
f = 1:10000;
fc1pole_low = 1/(R1*C1);
fc2pole_low = 1/sqrt(R1*R2*C1*C2);
f_zero = 1/(R1*C1);
f_pole = 1/((C1*R1*R2)/(R1+R2));
fczero = 1/(R1*C1);
fcpole = 1/((C1*R1*R2)/(R1+R2));
fczero_new = 2*fczero; %6db
C1G = zeros(1,max(f));
C2G = zeros(1,max(f));
C2GEq = zeros(1,max(f));
C2GUnc = zeros(1,max(f));
C3G = zeros(1,max(f));
for z = 1:length(f)
C1G(z) = 1/(1+1j.*z.*R1.*C1);
C2G(z) = (1/(1+1j*z*R1*C1))*(1/(1+1j*z*R2*C2));
C2GEq(z) = 1/(1-(z*R1*C1)^2+1j*z*3*R2*C2);
C2GUnc(z) = (1/(1+1j*z*R1*C1))^2;
C3G(z) = (R2/(R1+R2))*((1+1j*z*R1*C1)/(1+1j*z*C1*(R1*R2/(R1+R2))));
end
Amplitude =@(G) 20.*log10(abs(G));
Phase =@(G) atan(imag(G)./real(G));
C1amp = Amplitude(C1G);
C1phase = Phase(C1G);
figure
plot(f,C1amp)
figure
plot(f,C1phase)
  1 Comment
Steven Lord
Steven Lord on 3 Oct 2016
The atan function returns angles in radians, not degrees. Consider atand or atan2d instead.

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 3 Oct 2016
Edited: David Goodmanson on 4 Oct 2016
One possible reason is that R is about 1 kohm and C is about 300pF. This gives you an RC time constant of about .3 usec and a break point 1/(2piRC) at about 500 KHz. The frequencies of interest are only a few kHz, so the filter lets everything through and doesn't do anything. It appears that either the frequencies of interest have to be larger or one of R and C is too small.

Categories

Find more on Circuit Envelope Simulation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!