Another question related to my low-pass filter. Basically, I can calculate the frequency response of the circuit, one frequency at a time, using Matlab; what I can't figure out is how to use this method to calculate the response for a whole bunch of frequencies at once. Maybe someone can help me out. Here are the calculations for a single frequency at a time:
EDU>> % The circuit analysis calculations are: EDU>> % (Vin - V2)/R2 + (Vout - V2)/c2 = (V2 - Vout)/R4 EDU>> % (V2 - Vout)/R4 = Vout/c1
EDU>> % Re-arranging.... EDU>> % V2*(-1/R2 - 1/c2 - 1/R4) + Vout*(1/c2 + 1/R4) = -Vin/R2 EDU>> % V2*(1/R4) + Vout*(-1/R4 - 1/c1) = 0
So the goal is to set up a matrix: Vm * V = Vr, and then calculate: V = inv(Vm) * Vr. Again, for a single frequency:
EDU>> f=2500; EDU>> w=2*pi*f; EDU>> R2=330; EDU>> R4=1000; EDU>> c1=1./(j.*w.*470e-9); EDU>> c2=c1; EDU>> Vin=1; EDU>> Vm = [(-1/R2 - 1/c2 - 1/R4) (1/c2 + 1/R4) ; (1/R4) (-1/R4 -
1/c1)]; EDU>> Vr = [ -Vin/R2 ; 0 ]; EDU>> V=inv(Vm)*Vr; EDU>> abs(V) ans = 0.37972 0.050967The second value for "ans" correctly matches the measured output from the circuit at f = 2500 Hz; it also matches the result if I use the following equation to calculate the output voltage: EDU>> % Some pencil and paper work then yields EDU>> % Vout = (Vin/R2) / [(R4/c1) * (1/R2 + 1/c2) + 1/c1 + 1/R2]
So far, so good. And, with the formula for Vout, I can use an input vector f = [1 10 100 1000 etc.] for the input frequencies, and get a vector for the output voltages. But the fact that I had to work out a pencil and paper solution for Vout is not elegant. The elegant solution was the one shown above -- set up the matrix for the circuit behavor, and use V=inv(Vm)*Vr to let Matlab worry about the algebra.
The problem is when I try to combine the two approaches. That is, I use the matrix algebra above, culminating with V=inv(Vm)*Vr; and I also try to use an input vector for the frequencies, f = [1 10 100
1000 etc.], rather than a single value such as f = 1000. Matlab chokes on the Matrix algebra plus input vector. Specifically, what I get is:EDU>> f=[1 100 1000 2500]; EDU>> w=2*pi*f; EDU>> R2=330; R4=1000; c1=1./(j.*w.*470e-9); c2=c1; Vin=1; EDU>> Vm = [(-1./R2 - 1./c2 - 1./R4) (1./c2 + 1./R4) ; (1./R4) (-1./R4
- 1./c1)]; ??? Error using ==> vertcat All rows in the bracketed expression must have the same number of columns.
So right here, I'm stuck. I'll played with setting up the matrix in all kinds of ways -- this posting would run about 500 lines if I showed all of them -- but could not get this to work. Can someone kindly show me how to use the input vector f, while retaining the elegant matrix calculation approach?
In case anyone wants to see the circuit at hand, you can view it at:
Thanks in advance for all replies.
Steve O.
"Spying On The College Of Your Choice" -- How to pick the college that is the Best Match for a high school student's needs.