% Add sine waves and plot result.

f0 = 10;    % Frequency in Hz
w0 = 2*pi*f0;

t=0:.001:0.5;

v1 = 2*cos(w0*t);
v2 = 3*cos(w0*t - pi/4);
vsum = v1 + v2;

figure(1)
clf
subplot(211)
plot(t, v1, 'b-', t, v2, 'r-')
legend('v1', 'v2')
xlabel('TIME (sec)')
ylabel('AMPLITUDE')
title('v1 and v2 separately')
subplot(212)
plot(t, vsum,'k-')
xlabel('TIME (sec)')
ylabel('AMPLITUDE')
title('Sum:  v1 + v2')
grid

v1p = 2;
v2p = 3*exp(j*(-pi/4));
vsump = v1p + v2p;
figure(2)
plot([0 real(v1p)], [0, imag(v1p)], 'b-', ...
    [0 real(v2p)], [0, imag(v2p)], 'r-', ...
    [0 real(vsump)], [0, imag(vsump)], 'k-')
legend('PHASOR 1', 'PHASOR 2', 'PHASOR SUM')
xlabel('REAL')
ylabel('IMAG')
title('Phasor Sum')
axis([-1 5 -5 1])

