beamforming.m
function [res,theta,p,q]=beamforming(ang,N)
%Magnitude response of the received signal as the function of AOD (\theta)
%with three arrays
%phi is chosen for an angle 45 degree
%N is the number of antennas
lambda=5*10^(-3);
d=lambda/4;
phi=(2*pi*cos(ang))/(lambda);
theta=0:pi/1000:pi;
NUM=sin((N*d/2)*(2*pi*cos(theta)/lambda -phi));
DEN=sin((d/2)*(2*pi*cos(theta)/lambda -phi));
res=NUM./DEN;
[a]=isnan(res);
[c,d]=find(a==1);
res(d)=N;
[p,q]=max(res);
ang=[pi/8 pi/4 3*pi/8 5*pi/8];
N=[11 21 31 41];
for i=1:1:4
[res,theta,p,q]=beamforming(ang(i),N(i))
subplot(2,2,i)
plot(theta,res)
hold on, plot(theta(q),p,'*')
end
