Main Content

Generate MEX Function to Estimate Directions of Arrival

Compile, using codegen (MATLAB Coder), the function EstimateDOA.m. This function estimates the directions-of-arrival (DOA’s) of two signals with added noise that are received by a standard 10-element Uniform Line Array (ULA). The antenna operating frequency is 150 MHz and the array elements are spaced one-half wavelength apart. The actual direction of arrival of the first signal is 10° azimuth, 20° elevation. The direction of arrival of the second signal is 45° azimuth, 60° elevation. Signals and noise are generated using the sensorsig function.

function [az] = EstimateDOA()
% Example:
% Estimate the DOAs of two signals received by a standard
% 10-element ULA with element spacing one half-wavelength apart.
% The antenna operating frequency is 150 MHz.
% The actual direction of the first signal is 10 degrees in
% azimuth and 20 degrees in elevation. The direction of the
% second signal is 45 degrees in azimuth and 60 degrees in
% elevation.
c = physconst('LightSpeed');
fc = 150e6;
lambda = c/fc;
fs = 8000;
nsamp = 8000;
sigma = 0.1;
ang = [10 20; 45 60]';
antenna = phased.IsotropicAntennaElement( ...
    'FrequencyRange',[100e6,300e6]);
array = phased.ULA('Element',antenna,'NumElements',10, ...
    'ElementSpacing',lambda/2);
pos = getElementPosition(array)/lambda;
sig = sensorsig(pos,nsamp,ang,sigma^2);
estimator = phased.RootMUSICEstimator('SensorArray',array,...
    'OperatingFrequency',fc,...
    'NumSignalsSource','Property','NumSignals',2);
doas = estimator(sig);
az = broadside2az(sort(doas),[20,60]);
end

Run codegen (MATLAB Coder) at the command line to generate the mex function, EstimateDOA_mex, and then run the mex function:

codegen EstimateDOA.m
EstimateDOA_mex

The estimated arrival angles are:

az =

  10.0036   45.0030

The program contains a fixed value for the noise variance. If you wanted to reuse the same code for different noise levels, you can pass the noise variance as an argument into the function. This is done in the function EstimateDOA1.m, shown here, which has the input argument sigma.

function [az] = EstimateDOA1(sigma)
% Example:
% Estimate the DOAs of two signals received by a standard
% 10-element ULA with element spacing one half-wavelength apart.
% The antenna operating frequency is 150 MHz.
% The actual direction of the first signal is 10 degrees in
% azimuth and 20 degrees in elevation. The direction of the
% second signal is 45 degrees in azimuth and 60 degrees in
% elevation.
c = physconst('LightSpeed');
fc = 150e6;
lambda = c/fc;
fs = 8000;
nsamp = 8000;
ang = [10 20; 45 60]';
antenna = phased.IsotropicAntennaElement( ...
    'FrequencyRange',[100e6,300e6]);
array = phased.ULA('Element',antenna,'NumElements',10, ...
    'ElementSpacing',lambda/2);
pos = getElementPosition(array)/lambda;
sig = sensorsig(pos,nsamp,ang,sigma^2);
estimator = phased.RootMUSICEstimator('SensorArray',array, ...
    'OperatingFrequency',fc, ...
    'NumSignalsSource','Property','NumSignals',2);
doas = estimator(sig);
az = broadside2az(sort(doas),[20,60]);
end

Run codegen (MATLAB Coder) at the command line to generate the mex function, EstimateDOA1_mex, using the -args option to specify the type of input argument. Then run the mex function with several different input parameters:

codegen EstimateDOA1.m -args {1}
EstimateDOA1_mex(1)
az =
   10.0130   45.0613
EstimateDOA1_mex(10)
az =
   10.1882   44.3327
EstimateDOA1_mex(15)
az =
    8.1620   46.2440

Increasing the value of sigma degrades the estimates of the azimuth angles.