This slide generates a 3D antenna radiation pattern plot by coherently combining patterns from uniformly spaced elements with a progressive phase shift between them. The beam direction is steered by adjusting the starting phase and phase shift amount. Key steps: Create meshgrid of angles X,Y to plot antenna pattern over Set number of antenna elements n and spacing k Define phase p and phase shift amount s Loop over antenna elements, shifting phase each time Add up radiation pattern for each element Plot 3D radiation pattern surface from combined elements Show pattern from two view angles (angled above view and top view) Key parameters: n - number of antenna elements k - spacing between elements p - initial phase at first element s - phase shift amount between elements Varying n and k changes number of lobes Varying p and s steer the beam direction     < Code 1 >   function main    xstep = -10*pi:pi/10:10*pi; ystep = -10*pi:pi/10:10*pi;; [X,Y] = meshgrid(xstep,ystep);   n=8; % should be even integer k=2; p = 12*pi/4; s = (30*pi/60); m = 0;   Z = zeros(length(xstep)); for i = ((0:(n-1))-((n-1)/2))   [X1,Y1] = meshgrid(xstep+(i*pi/k),ystep);   Z = Z+(waveCosPh(X1,Y1,p+m*s,p));   m = m+1; end;   hFig = figure(1,'Position',[300 300 700 280]); subplot(1,2,1); surface(X,Y,Z,'edgecolor','none'); xlim([-10*pi 10*pi]);ylim([-10*pi 10*pi]);zlim([-10,10]); view([-40 70]); set(gca,'xticklabel',[]); set(gca,'yticklabel',[]); set(gca,'zticklabel',[]); set(gca,'xtick',[]); set(gca,'ytick',[]); set(gca,'ztick',[]);   subplot(1,2,2); surface(X,Y,Z,'edgecolor','none'); xlim([-10*pi 10*pi]);ylim([-10*pi 10*pi]);zlim([-10,10]); view([0 90]); set(gca,'xticklabel',[]); set(gca,'yticklabel',[]); set(gca,'zticklabel',[]); set(gca,'xtick',[]); set(gca,'ytick',[]); set(gca,'ztick',[]);   end   function z = waveCosPh(x,y,Ph,r)    d = sqrt(x.^2 + y.^2)-Ph;  dim = size(d);  dr = dim(1);  dc = dim(2);    for i = 1 : dr      for j = 1 : dc          if d(i,j) > r             d(i,j) = pi/2;          end;          end;       end;        %z = cos(d-Ph);  z = cos(d);   end