MATLAB - Forgot to add to thread title
Hi, this question is heavily based on my other thread http://forum.allaboutcircuits.com/showthread.php?t=79690
but I thought I would post another thread in there because It's more relevent and has more infomation.
So I'm generate 2 graphs with one being a current in the circuit and another a voltage across a capacitor.
Because I'm generating the square wave myself - I've been attempting to calculate the values with each of the sine waves that make up the square wave and add the results together. But Apparently my answer is incorrect - (my input is correct).
Can somebody take a quick look please !
my output
and the outputs for I(t) and the voltage of capacitor 3 apparently should look like
Hi, this question is heavily based on my other thread http://forum.allaboutcircuits.com/showthread.php?t=79690
but I thought I would post another thread in there because It's more relevent and has more infomation.
So I'm generate 2 graphs with one being a current in the circuit and another a voltage across a capacitor.
Because I'm generating the square wave myself - I've been attempting to calculate the values with each of the sine waves that make up the square wave and add the results together. But Apparently my answer is incorrect - (my input is correct).
Can somebody take a quick look please !
Rich (BB code):
%Constants
%%%%%%%%%%%%%%
T=1e-9;
omega = (2*pi)/T;
t = 0:0.1e-11:3e-9;
c1 = 250e-12;
c2 = 250e-12;
c3 = 250e-12;
r1 = 0.5;
r2 = 1;
zc1 = 1/(1i*omega*c1);
zc2 = 1/(1i*omega*c2);
zc3 = 1/(1i*omega*c3);
zr1 = r1;
zr2 = r2;
zmatrix=[zc1, -zc1, 0
-zc1, zc1+zr1+zc2+zr2, -zr2
0, -zr2, zr2+zc3];
zinv = inv(zmatrix);
for n=0:200
Vin = zeros(3, length(t));
Vin(1,:) = (1/(2*n+1))*sin((2*n + 1)*omega*t);
Itemp = zinv*Vin;
if n == 0
I= Itemp;
Vtotal = Vin(1,:);
Vc3 = I(3,:)*zc3;
else
I = I + Itemp;
Vtotal = Vtotal + Vin(1,:);
Vc3 = Vc3 + I(3,:)*zc3;
end
end
figure(1)
subplot(311)
plot(t, Vtotal)
title('Input v(t)')
xlabel('time (s)')
ylabel('Voltage (V)')
subplot(312)
plot(t, I(2,:))
title('I(t)')
xlabel('time / s')
ylabel('Current (A)')
subplot(313)
plot(t, Vc3)
title('Voltage Cap 3')
xlabel('time (s)')
ylabel('Voltage (V)')
and the outputs for I(t) and the voltage of capacitor 3 apparently should look like