Reducing the computation time of the planar antenna array pattern calcuation

Hi, i'm calculating the planar antenna array pattern, the problem is that it takes ~10s to calculate the pattern, and i need to calculate it a lot of times in my algorithm. The majority of time is spent to calculate the for loop. Please advise me how can i reduce the for loop execution time, or replace it with some other solution. Thanks in advance.
clc; close all; clear all;
Nx=32; Ny=32;
betta_n = zeros(Nx,Ny); lambda=1;
dx = [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 ];
dy = [1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 1.5 ];
a_n = ones(Nx, Ny);
dtetta = 0.01;
dphi = 0.01;
tetta0 = -pi/2:dtetta:pi/2;
phi0 = dphi:dphi:2*pi;
[phi, tetta] = meshgrid(phi0,tetta0);
j = sqrt(-1);
amp_phase=a_n.*(cos(betta_n)+j*sin(betta_n));
sinU=sin(tetta).*cos(phi);
sinV=sin(tetta).*sin(phi);
% AF_Field = 0;
AF_Field = zeros(length(tetta0),length(phi0));
tic
for n=1:Nx-1
for m=1:Ny-1
%calculate each of the exponents separately wo the loop
AF_Field = amp_phase(n,m)*exp(j*2*pi*(n-1)/lambda*dx(n)*(sinU)).*exp(j*2*pi*(m-1)/lambda*dy(m)*(sinV)) + AF_Field;
end
end
toc

Answers (1)

The main computational cost comes from repeatedly evaluating the exponential terms over the entire (θ, ϕ) grid inside the nested loops. To improve performance, precompute the x- and y-direction phase terms and reuse them, or express the array factor as a matrix operation to eliminate the double loop.
Additional options:
  • Cache the phase terms if the array geometry is fixed.
  • Use parfor or GPU acceleration for large optimization runs.
  • Use the MATLAB Profiler to identify remaining bottlenecks.

Categories

Asked:

on 20 May 2017

Answered:

on 30 Sep 2026 at 8:28

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!