AC circuit analysis from today’s lab

AC_waveforms


%
% AC circuit analysis example
% Written by Ted Burke 8-3-2016
%

% Define j, the square root of -1
j = 0 + 1i;

% Define the freqeuency in the circuit
f = 50;
w = 2 * pi * f;

Vs = 2; % Voltage source (reference phasor)
R = 100; % resistance
C = 10e-6; % capacitance

% Convert each RLC element into an impedance
Zr = R;
Zc = 1 / (j * w * C);

Vc = Vs * Zc / (Zc + Zr); % calculate capacitor voltage
I = Vs / (Zr + Zc); % calculate current

% Convert phasors (complex numbers) into time signals
t = [0:0.0001:0.05];
vs = real(sqrt(2) * Vs * exp(j*w*t));
vc = real(sqrt(2) * Vc * exp(j*w*t));
i = real(sqrt(2) * I * exp(j*w*t));

% Plot sinusoidal voltages and current
set(gca,'fontsize',18)
hold on
plot(t, vs , 'r', 'LineWidth', 2)
plot(t, vc , 'g', 'LineWidth', 2)
plot(t, 1000*i, 'b', 'LineWidth', 2)
title('Voltages and Current')
legend('v_S(t) [V]', 'v_C(t) [V]', 'i(t) [mA]')
xlabel('time [s]')
text(0.001,9,['r.m.s. magnitude of vs(t) = ' num2str(abs(Vs)) ' V'])
text(0.001,8,['r.m.s. magnitude of vc(t) = ' num2str(abs(Vc)) ' V'])
text(0.001,7,['r.m.s. magnitude of i(t) = ' num2str(1000 * abs(I)) ' mA'])
text(0.001,6,['angle(Vc) = ' num2str(angle(Vc)) ' rad'])
text(0.001,5,['angle(I) = ' num2str(angle(I)) ' rad'])
hold off

Leave a comment