% This is a simulation to model the Elam SDMA technique
% Developed by Frank B. Gross, November 11, 2004
% define the sample baseband modulation initially as a 1kHz phase modulation tone
% WALSH FUNCTIONS WORK BETTER THAN PN SEQUENCES
% Can also use Gold codes
f=1E3;
T=1/(4*f);
Nchips=64;
tend=20*Nchips;
t=[0:(tend-1)]*T/(tend-1);
m=sin(2*pi*f*t); % modulation m
m=zeros(1,length(m));
% plot array factor for linear array
N=11; % number of receive elements to give 10 degree beamwidth
d=.5; % spacing in wavelengths between adjacent array elements
theta=0:.01:pi;
% generate pseudo-random 50 chip codes T long to modulate the
% received signals from each antenna
binary % generate the N pseudo-noise binary codes
test=-30*pi/180;
test=0;
test2=45*pi/180;
Vr=zeros(181,length(t));
Vr2=zeros(181,length(t));
er=zeros(181,length(t));
for k=1:181;
an(k)=(k-1)-90;
th(k)=an(k)*pi/180;
% calculate the actual received signal for each angle using the N=11 element
% receiver and sum all N signals.
for i=1:N
Vr(k,:)=Vr(k,:)+exp(1j*(m+2*pi*(i-1)*d*sin(test)+codes(i,:))); % create combined signal at angle j
Vr2(k,:)=Vr2(k,:)+exp(1j*(m+2*pi*(i-1)*d*sin(test2)+codes(i,:)));
er(k,:)=er(k,:)+exp(1j*(2*pi*(i-1)*d*sin(th(k))+codes(i,:)));
end
%Vr(k,:)=Vr(k,:)+Vr2(k,:);
R1(k)=sum(Vr(k,:).*er(k,:));
R2(k)=sum(Vr(k,:).*conj(er(k,:)));
%phase1(k,:)=unwrap(angle(Vr(k,:).*conj(er(k,:))));
%phase2(k,:)=unwrap(angle(Vr(k,:).*(er(k,:))));
phase1(k,:)=unwrap(angle(R1(k)));
phase2(k,:)=unwrap(angle(R2(k)));
end
AF=sin(N*pi*d*(sin(th)-sin(test)))./(N*sin(pi*d*(sin(th)-sin(test))));
maxAF=max(abs(AF));
maxR2=max(abs(R2));
maxR1=max(abs(R1));
figure;
plot(an,abs(R2)/maxR2,'k',an,abs(AF),'k:')
xlabel('\theta')
ylabel('Correlation Magnitude')
title('N=20 elements, d=\lambda/2, Nchips=64')
axis([-90 90 0 1])
grid on
%title('correlation comparison \theta_k =45^0')
%legend('correlation')
%figure;
%plot(t,m,'k',t,phase1(46,:),'k:',t,phase2(46,:),'k-.')
%xlabel('t')
%ylabel('phase')
%title('comparison of instantaneous and averaged phases')
%legend('phase m(t)','avg w/o conjugate','avg with conjugate')