# Documentation

## Direction of Arrival Estimation with Beamscan and MVDR

This example illustrates using beamscan and MVDR for direction of arrival (DOA) estimation. Beamscan is a technique that forms a conventional beam and scans it over directions of interest to obtain a spatial spectrum. Minimum variance distortionless response (MVDR) is similar to beamscan but uses an MVDR beam. The peaks of the output spatial spectrum indicate the DOAs of the received signals. In this example, we illustrate the use of beamscan and MVDR to estimate broadside angles with a uniform linear array (ULA) and azimuth and elevation angles with a uniform rectangular array (URA).

First, we model a uniform linear array (ULA) containing 10 isotropic antennas. The adjacent antenna spacing is 0.5 meters.

```ha = phased.ULA('NumElements',10,'ElementSpacing',0.5); ```

Assume that two narrowband signals impinge on the array. The first signal arrives from 40 degrees in azimuth and 0 degrees in elevation, while the second signal arrives from -20 degrees in azimuth and 0 degrees in elevation. The operating frequency of the system is 300 MHz.

```ang1 = [40; 0]; % First signal ang2 = [-20; 0]; % Second signal angs = [ang1 ang2]; c = physconst('LightSpeed'); fc = 300e6; % Operating frequency lambda = c/fc; pos = getElementPosition(ha)/lambda; Nsamp = 1000; ```

We also assume that the thermal noise at each antenna has a power of 0.01 Watts.

```nPower = 0.01; ```

We generate the multichannel signal received by the ULA.

```rs = rng(2007); x = sensorsig(pos,Nsamp,angs,nPower); ```

### Beamscan DOA Estimation with a ULA

We want to estimate the two DOAs using the received signal. Since the signal is received by a ULA, which is symmetric around its axis, we cannot obtain both azimuth and elevation at the same time. Instead, we can estimate the broadside angle, which is measured from the broadside of the ULA. The relationship between these angles is illustrated in the following figure:

The broadside angles corresponding to the two incident directions are:

```broadsideAngle = az2broadside(angs(1,:),angs(2,:)) ```
```broadsideAngle = 40.0000 -20.0000 ```

We can see that the two broadside angles are the same as the azimuth angles. In general, when the elevation angle is zero and the azimuth angle is within [-90 90], the broadside angle is the same as the azimuth angle. In the following we only perform the conversion when they are not equal.

The beamscan algorithm scans a conventional beam through a predefined scan region. Here we set the scanning region to [-90 90] to cover all 180 degrees.

```hBeamscan = phased.BeamscanEstimator('SensorArray',ha,... 'OperatingFrequency',fc,'ScanAngles',-90:90); ```

By default, the beamscan estimator only produces a spatial spectrum across the scan region. We can set the DOAOutputPort property to true to obtain an estimation of DOAs. We set the NumSignals property to 2 to find the locations of the top two peaks.

```hBeamscan.DOAOutputPort = true; hBeamscan.NumSignals = 2; ```

We can now call the step method to obtain the spatial spectrum and the DOAs. The estimated DOAs show the correct values, which are 40 and -20 degrees.

```[~,ang] = step(hBeamscan,x) ```
```ang = 40 -20 ```

We can plot the spatial spectrum of the beamscan output.

```plotSpectrum(hBeamscan); ```

### Improving Resolution Using an MVDR Estimator

The conventional beam has a limitation in resolving two closely-spaced signals. When two signals arrive from directions separated by less than the beamwidth, the above method will fail to estimate the directions of the signals. To illustrate this limitation, we simulate two received signals from 30 and 40 degrees in azimuth.

```ang1 = [30; 0]; ang2 = [40; 0]; x = sensorsig(pos,Nsamp,[ang1 ang2],nPower); [~,ang] = step(hBeamscan,x) ```
```ang = 35 71 ```

The results are different from the true azimuth angles. Let's take a look at the output spectrum.

```plotSpectrum(hBeamscan); ```

The output spatial spectrum has only one dominant peak. Therefore, it cannot resolve these two closely-spaced signals. When we try to estimate the DOA from the peaks of the beamscan output, we get incorrect estimates. The beamscan object returns two maximum peaks as the estimated DOAs no matter how different the peaks are. In this case, the beamscan returns the small peak at 71 degrees as the second estimate.

To resolve these closely-spaced signals, we can use the minimum variance distortionless response (MVDR) algorithm. The MVDR estimator scans an MVDR beam over the specified region. Because an MVDR beam has a smaller beamwidth, it has higher resolution.

```hMVDR = phased.MVDREstimator('SensorArray',ha,... 'OperatingFrequency',fc,'ScanAngles',-90:90,... 'DOAOutputPort',true,'NumSignals',2); [~,ang] = step(hMVDR,x) plotSpectrum(hMVDR); ```
```ang = 30 40 ```

The MVDR algorithm correctly estimates the DOAs that are unresolvable by beamscan. The improved resolution does not come without a price. The MVDR is more sensitive to sensor position errors. In circumstances where sensor positions are inaccurate, MVDR could produce a worse spatial spectrum than beamscan. Moreover, if we further reduce the difference of two signal directions to a level that is smaller than the beamwidth of an MVDR beam, the MVDR estimator will also fail. For a ULA, there are other higher resolution algorithms that can further exploit the special geometry of the ULA. See High Resolution Direction of Arrival Estimation

### Converting Broadside Angles to Azimuth

Although we can only estimate broadside angles using a ULA, we can convert the estimated broadside angles to azimuth angles once we have the knowledge of their incoming elevations. We now model two signals coming from 35 degrees in elevation and estimate their corresponding broadside angles.

```ang1 = [40; 35]; ang2 = [15; 35]; x = sensorsig(pos,Nsamp,[ang1 ang2],nPower); [~,ang] = step(hMVDR,x) ```
```ang = 32 12 ```

The resulting broadside angles are different from either the azimuth or elevation angles. We can convert the broadside angles to the azimuth angles if we know the elevation.

```ang = broadside2az(ang,35) ```
```ang = 40.3092 14.7033 ```

### Beamscan DOA Estimation with a URA

Next, we illustrate DOA estimation using a uniform rectangular array (URA). A URA can estimate both azimuth and elevation angles. We model a URA with 10 rows and 5 columns. The element spacing is 0.3 meters between each row, and 0.5 meters between each column.

```hURA = phased.URA('Size',[10 5],'ElementSpacing',[0.3 0.5]); ```

Assume that two signals impinge on the URA. The first signal arrives from 40 degrees in azimuth and 45 degrees in elevation, while the second signal arrives from -20 degrees in azimuth and 20 degrees in elevation.

```ang1 = [40; 45]; % First signal ang2 = [-20; 20]; % Second signal x = sensorsig(getElementPosition(hURA)/lambda,Nsamp,[ang1 ang2],nPower); rng(rs); % Restore random number generator ```

We now create a 2D beamscan estimator object and associate the URA with it. This object uses the same algorithm as the 1D case except that it scans over both azimuth and elevation instead of broadside angles.

The scanning region is specified by the property 'AzimuthScanAngles' and 'ElevationScanAngles'. To reduce computational complexity, we assume some a priori knowledge about the incoming signal directions. We restrict the azimuth scan region to [-45 45] and the elevation scan region to [10 60].

```hDOA = phased.BeamscanEstimator2D('SensorArray',hURA,... 'OperatingFrequency',fc,... 'AzimuthScanAngles',-45:45,'ElevationScanAngles',10:60,... 'DOAOutputPort',true,'NumSignals',2); ```

The DOA output is an N-by-2 matrix where N is the number of signal directions. The first column contains azimuth angles while the second column contains elevation angles.

```[~,ang] = step(hDOA,x) ```
```ang = 40 -20 45 20 ```

We now plot the spatial spectrum. The spectrum is a 3D plot because we scan the beam in both azimuth and elevation angles.

```plotSpectrum(hDOA); ```

### MVDR DOA Estimation with a URA

Similar to the ULA case, we can use a 2D version of the MVDR algorithm. Since our knowledge of the sensor positions is perfect, we expect the MVDR spectrum to have a better resolution than beamscan.

```hMVDR = phased.MVDREstimator2D('SensorArray',hURA,... 'OperatingFrequency',fc,... 'AzimuthScanAngles',-45:45,'ElevationScanAngles',10:60,... 'DOAOutputPort',true,'NumSignals',2); [~,ang] = step(hMVDR,x) plotSpectrum(hMVDR); ```
```ang = -20 40 20 45 ```

### Summary

In this example, we showed how to apply the beamscan and MVDR techniques to the DOA estimation problem. We used both techniques to estimate broadside angles for the signals received by a ULA. The MVDR algorithm has better resolution than beamscan when there is no sensor position error. We also illustrated how to convert between azimuth and broadside angles. Next, we applied beamscan and MVDR to estimate both azimuth and elevation angles using a URA. In all of these cases, we plotted the output spatial spectrum. Beamscan and MVDR are techniques that can be applied to any type of array, but for ULAs and URAs there are other higher resolution techniques that can further exploit the array geometry.