clear all;
clf;

% This code will generate 5-second sample runs of X(t) and
% Y(t) and print out the corresponding plots.

% First, select 5 random phases (either pi/2 or -pi/2 with equal probability).
% WRITE MATLAB CODE HERE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
theta_n = pi/2*(2*randi(2,5,1)-3);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Replicate theta_n so that each random phase covers a 100-step time range.
theta_t = ones(1,100) * theta_n(1);

for i=2:5
theta_t = [theta_t ones(1,100)*theta_n(i)];
end

% Generate the time steps corresponding to theta_t.
t=0:.01:4.99;

% Generate the values of X(t).
% WRITE MATLAB CODE HERE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X_t = cos(4*pi*t+theta_t);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(2,1,1);
plot(t, X_t);
xlabel('t');
ylabel('X(t)');
title('Part a');

% Generate the values of Y(t). (Don't forget to generate "psi"!)
% WRITE MATLAB CODE HERE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
psi = 2*pi*rand(1);
Y_t = cos(4*pi*t+theta_t+psi);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(2,1,2);
plot(t, Y_t);
xlabel('t');
ylabel('Y(t)');
title('Part c');
% print -depsc2 pskModulationFigure;