% 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
theta=0:pi/4:7*pi/4;    % Vary theta from 0 to 7*pi/4
N=6;                    % N incomming signals
onet=ones(1,length(t));

color=['brgkbrgk'];     % Plot with different colors

% Print results of different theta's vs. time
subplot(211)
hold on
grid
x=A*N*cos(w*t);
plot(t,x,color(1))
for i=2:length(theta)
    x=A*sin(N*theta(i)/2)/sin(theta(i)/2)*cos(w*t+(N-1)/2*theta(i)*onet);
    plot(t,x,color(i))
end
s=['Sum of ' num2str(N) ' Sinusoids Evenly Phased In Time For Various Theta''s'];
title(s)
xlabel('Time'), ylabel('x(t)')

% Plot Magnitude and Phase vs psi
theta=-2*pi:pi/500:2*pi;
inter=sin(N*theta/2)./sin(theta/2).*exp(j*(N-1)/2*theta);
mag_theta=abs(inter);
ang_theta=angle(inter);

subplot(223)
hold on
grid
plot(theta,mag_theta)
axis tight
title('Magnitude vs. theta')
xlabel('Phase Angle (theta) in radians')
ylabel('Magnitude')

subplot(224)
hold on
grid
plot(theta,ang_theta)
max_ang=max(abs(ang_theta));
axis([-2*pi 2*pi -max_ang max_ang])
title('Angle vs. theta')
xlabel('Phase Angle (theta) in radians')
ylabel('Angle')
