% DEMO:         INTERFERENCE PATTERN DEMO
%
% Program:      interference_pattern.m
% Written by:   
% For:          EE 311
%               Computer Lab 2
% Date:         7-11-2001
% Purpose:     
%
% Purpose:      Interference Experiment
clear all, hold off, clf reset, close all
j=sqrt(-1);

A=1;                    % Pick an amplitude of 1
f=2000;                 % Chose a frequency of 2000
w=2*pi*f;               % Calculate omega from f
T=1/f;                  % Find period
t=-2*T:T/200:2*T;       % Pick 200 points for time axis
phi=0;                  % Pick a phi
psi_vary=0:pi/4:7*pi/4; % Vary psi from 0 to 7*pi/4
onet=ones(1,length(t));

color=['brgmckyb'];     % Plot with different colors

% Print results of different psi's vs. time
subplot(211)
x1=A*cos(w*t-phi*onet);
hold on
grid
for i=1:length(psi_vary)
    x2=A*cos(w*t-phi*onet-psi_vary(i)*onet);
    x=x1+x2;
    plot(t,x,color(i))
end    
title('Sum of Two Sinusoids vs. Time')
xlabel('Time'), ylabel('x(t)')

% Plot Magnitude and Phase vs psi
psi=-2*pi:pi/50:2*pi;
inter=2*A*cos(psi/2).*exp(-j*(phi+(psi/2)));
mag_psi=abs(inter);
ang_psi=angle(inter);

subplot(223)
hold on
grid
plot(psi,mag_psi)
axis tight
title('Magnitude vs. psi')
xlabel('Phase Angle (psi) in radians')
ylabel('Magnitude')

subplot(224)
hold on
grid
plot(psi,ang_psi)
max_ang=max(abs(ang_psi));
axis([-2*pi 2*pi -max_ang max_ang])
title('Angle vs. psi')
xlabel('Phase Angle (psi) in radians')
ylabel('Angle')