Code

Beampattern of a Linear Array of Antennas (Array Processing)

Miguel De Jesus Rosario November 30, 20101 comment Coded in Matlab

The function pattern() computes and plots the beampattern of a Linear Array of sensors. This function has three inputs: the number of elements in the array, the pointing direction of the beam pattern (an angular direction in radians), and a constant spacing between the elements of the array (as fraction of the wavelenght (lambda).  The optimum spacing between elements of the array is 0.5. You must also select any of the windows presented in the menu. Windowing techniques are used to reduced the sidelobes of the pattern.  

The list of available windows is the following:

%           @bartlett       - Bartlett window.
%           @barthannwin    - Modified Bartlett-Hanning window.
%           @blackman       - Blackman window.
%           @blackmanharris - Minimum 4-term Blackman-Harris window.
%           @bohmanwin      - Bohman window.
%           @chebwin        - Chebyshev window.
%           @flattopwin     - Flat Top window.
%           @gausswin       - Gaussian window.
%           @hamming        - Hamming window.
%           @hann           - Hann window.
%           @kaiser         - Kaiser window.
%           @nuttallwin     - Nuttall defined minimum 4-term Blackman-Harris window.
%           @parzenwin      - Parzen (de la Valle-Poussin) window.
%           @rectwin        - Rectangular window.
%           @tukeywin       - Tukey window.
%           @triang         - Triangular window.

For example:      pattern(21, pi/4, 0.5);
           Plots the beampattern of an linear array with 21 elements equally spaced 
           at a half of the wavelenght(lambda/2), and a pointing
           direction of 45 degrees. For uniform arrays use a rectangular
           window (rectwin).

NOTE: This code has two different functions: 1) pattern()   2) NDFT2().  The function NDFT2 is called in the function pattern().  You must save as m-file each function in the same directory.

% The function NDFT2 computes the sinc pattern of a linear array of 
% sensors. The function receives three input: the interelement spacing d,
% the array weigths a, and the zero padding desired Npad.

function NDFT2(d, a, Npad)

k  = -Npad/2 : Npad/2-1; % index
u  = pi*k/Npad; % u is a vector with elements in the range of -pi/2 to pi/2
uk = sin(u);
n  = 0:Npad-1; % n is an index
m  = 1:Npad; % m is an index

% Wavenumber K = 2*pi/landa 
% d = is a fraction or a multiple of lambda.
% v = K*d*uk(m).
  
v = 2*pi*d*uk(m)';
Dn(m,n+1) = exp(j*v*n);

puk = Dn * a'; % Computing the Beampattern

% Plot of the Beampatterns
figure(1); subplot(2,1,1); plot(uk,20*log10(abs(puk)));grid on; xlabel('sin(theta)'); ylabel('Magnitude (dB)')
axis([-1 1 -100 0])
subplot(2,1,2); plot(uk,puk);grid on; xlabel('sin(theta)'); ylabel('Magnitude')
axis([-1 1 -1 1])
warning off;
% Plot the beampattern as a polar graph
figure(2); polar(u',puk); hold on; polar(-u',puk);hold off         

%  Function pattern()
%
%     The function pattern() computes and plots the beampattern of a 
%     Linear Array of sensors. This function has three inputs: the number of elements in
%     the array, the pointing direction of the beam pattern (an angular
%     direction in radians), and a constant spacing between the elements of 
%     the array (as fraction of the wavelenght(lambda)of the transmitted  
%     signal.  The optimum spacing between elements of the array is 0.5. 
%     You must also select any of the windows presented in the menu. 
%     Windowing techniques are used to reduced the sidelobes of the pattern.   
%     The list of available windows is the following:
%
%           @bartlett       - Bartlett window.
%           @barthannwin    - Modified Bartlett-Hanning window. 
%           @blackman       - Blackman window.
%           @blackmanharris - Minimum 4-term Blackman-Harris window.
%           @bohmanwin      - Bohman window.
%           @chebwin        - Chebyshev window.
%           @flattopwin     - Flat Top window.
%           @gausswin       - Gaussian window.
%           @hamming        - Hamming window.
%           @hann           - Hann window.
%           @kaiser         - Kaiser window.
%           @nuttallwin     - Nuttall defined minimum 4-term Blackman-Harris window.
%           @parzenwin      - Parzen (de la Valle-Poussin) window.
%           @rectwin        - Rectangular window.
%           @tukeywin       - Tukey window.
%           @triang         - Triangular window.
%
%     For example:      pattern(21, pi/4, 0.5);
%           Plots the beampattern of an linear array with 21 elements equally spaced  
%           at a half of the wavelenght(lambda/2), and a pointing
%           direction of 45 degrees. For uniform arrays use a rectangular 
%           window (rectwin).

function pattern(array_number, angular_direction, spacing)

close all
clc

N = array_number;
delta = angular_direction;
d = spacing;

Npad=1024;
n=0:N-1;

delta = 2*pi*d*sin(delta);
an=1/N*exp(j*n*delta);

for i=0:500000,
    
option = menu('Choose the desired Window', 'Bartlett', 'Barthannwin', 'Blackman', 'Blackmanharris', 'Bohmanwin', 'Chebwin', 'Flattopwin', 'Gausswin', 'Hamming', 'Hann', 'Kaiser', 'Nuttallwin', 'Parzenwin', 'Rectwin', 'Tukeywin', 'Triang', 'Exit'); 

switch option
    
    case 1
        close all
        clear a;
        a=an;
        a = a.*bartlett(N)';
        a(Npad)=0;
      
        NDFT2(d, a, Npad);
        
        
    case 2
        close all
        clear a;
        a=an;
        a = a.*barthannwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
        
    case 3
        close all 
        clear a;
        a=an;
        a = a.*blackman(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
    case 4
        close all  
        clear a;
        a=an;
        a = a.*blackmanharris(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
    case 5
        close all 
        clear a;
        a=an;
        a = a.*bohmanwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
    case 6
        close all 
        clear a;
        a=an;
        a = a.*chebwin(N,40)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
    case 7
        close all
        clear a;
        a=an;
        a = a.*flattopwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);
        
    case 8
        close all 
        clear a;
        a=an;
        a = a.*gausswin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 9
        close all  
        clear a;
        a=an;
        a = a.*hamming(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 10
        close all 
        clear a;
        a=an;
        a = a.*hann(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 11
         close all
         clear a;
        a=an;
        a = a.*kaiser(N,1)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 12
         close all
         clear a;
        a=an;
        a = a.*nuttallwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 13
         close all 
         clear a;
        a=an;
        a = a.*parzenwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 14
         close all 
         clear a;
        a=an;
        a = a.*rectwin(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 15
         close all  
         clear a;
        a=an;
        a = a.*tukeywin(N,0)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 16
        close all
        clear a;
        a=an;
        a = a.*triang(N)';
        a(Npad)=0;

        NDFT2(d, a, Npad);

    case 17
        
        break;
              
    end
    
end