%matlab script for ps2 Need N=number of elements and d=element spacing % in wavelengths dct=0.0002; ct=-1:dct:1; %define equally spaced cos(theta) vector ct=ct+eps; %offset slightly so cos(theta) is never zero t=acosd(ct); %get the corresponding theta vector p=(1-ct.^2).*(sin(pi*N*d*ct)./sin(pi*d*ct)).^2; %power pattern intp=dct*sum(p); %integrate P(cos(theta)) wrt cos(theta) g=p*2/intp; %normalize to get the gain lg=10*log10(g); %get log10(gain) figure(1); plot(ct,lg) grid ax=axis; ax(3)=ax(4)-40; axis(ax); figure(2); plot(t,lg) grid ax2=axis; ax2(3)=ax2(4)-40; axis(ax2); %get the -3dB width in theta gmax=max(g); w1=find(g > gmax/2,1,'first'); w2=find(g > gmax/2,1,'last'); width=t(w1)-t(w2)