% SumSinus - add two sinusoids
%
% Numerical demonstration of an example worked in class. The sum of two
% sinusoidal signal is computed numerically and then compared to the result
% derived in class.

%% Parameters of the two sinusoids to be added
A1 = 3;
phi1 = 0;

A2 = 4;
phi2 = pi/2;

f=100;

fs = 5000;

%% compute 5 cycles of the two sinusoids
tt = 0:1/fs:5/f;
x1 = A1*cos(2*pi*f*tt+phi1);
x2 = A2*cos(2*pi*f*tt+phi2);

%% add the sinusoids
xx = x1+x2;

%% parameters of the sum - as computed in class
Ac = 5;
phic = atan(4/3);
xc = Ac*cos(2*pi*f*tt+phic);

%% nice plot with legend
plot(tt,x1,tt,x2,tt,xx,tt,xc,'k--');
xlabel('Time(s)')
ylabel('Amplitude')
grid
legend('x_1(t)','x_2(t)','x_1(t)+x_2(t)','computed','Location','EastOutside')