# Beamforming using MATLAB

I'm attempting to beamform some data which has signals coming from all directions in a 180 degree range.

I found an example of using the phased array toolbox, in MATLAB, to beamform a signal in https://uk.mathworks.com/help/phased/examples/conventional-and-adaptive-beamformers.html however, when I added a second signal from a different direction, the results aren't what I would expect.

If the two signals are coming from directions which are symmetrical about 90 degrees, i.e. 30 and 150 or 70 and 110, the beam forming algorithm cannot separate them. Is there a way of suppressing the signal coming from the other direction?

The code below is an example of what I mean where two signals are incoming from 30 and 150 degrees and then the beamforming algorithm is trying to isolate the signal from 30 degrees.

clear;
clc;
close;
t = 0:0.001:0.3;                % Time, sampling frequency is 1kHz
s = zeros(size(t));
s = s(:);                       % Signal in column vector
s(201:205) = s(201:205) + 1;    % Define the pulse
s_2 = zeros(size(t));
s_2 = s_2(:);                       % Signal in column vector
s_2(41:47) = s_2(41:47) + 1;    % Define the pulse
figure(1)
plot(t,s, t, s_2);
title('Pulse');xlabel('Time (s)');ylabel('Amplitude (V)');
carrierFreq = 30e6;
wavelength = physconst('LightSpeed')/carrierFreq;
ula = phased.ULA('NumElements',10,'ElementSpacing',wavelength/2);
ula.Element.FrequencyRange = [90e5 110e6];
inputAngle = [30; 0];
x = collectPlaneWave(ula,s,inputAngle,carrierFreq);
inputAngle2 = [150; 0];
x2 = collectPlaneWave(ula,s_2,inputAngle2,carrierFreq);
rs = RandStream.create('mt19937ar','Seed',2008);
noisePwr = .5;   % noise power
noise = sqrt(noisePwr/2)*(randn(rs,size(x))+1i*randn(rs,size(x)));
rxSignal = x + x2 + noise;
figure()
subplot(211);
plot(t,abs(rxSignal(:,1)));axis tight;
title('Pulse at Antenna 1');xlabel('Time (s)');ylabel('Magnitude (V)');
subplot(212);
plot(t,abs(rxSignal(:,2)));axis tight;
title('Pulse at Antenna 2');xlabel('Time (s)');ylabel('Magnitude (V)');
psbeamformer = phased.PhaseShiftBeamformer('SensorArray',ula,...
'OperatingFrequency',carrierFreq,'Direction',inputAngle,...
'WeightsOutputPort', true);
[yCbf,w] = step(psbeamformer, rxSignal);
figure()
plot(t,abs(yCbf)); axis tight;
title('Output of Phase Shift Beamformer');
xlabel('Time (s)');ylabel('Magnitude (V)');


Is it possible to get the signal from just one direction if the signal composes of reflected energy from all directions?- And if so, how?

• What is the separation in wavelength of your two antennas? – Dan Boschen Dec 19 '16 at 12:52
• There are 10 antennas in this case and they're separated by a distance of half the carrier wavelength: – RH_data_maths Dec 19 '16 at 13:17
• (ula = phased.ULA('NumElements',10,'ElementSpacing',wavelength/2);) – RH_data_maths Dec 19 '16 at 13:18
• With a linear array you cannot distinguish between left and right - so depending how you've defined where 0 deg is, you may be encountering this issue. If you 0 deg is the endfire beam ( aligns with the axis of the array) then beams +/- XXX degrees are indistinguishable. The beam patterns are symmetric about the long axis of the ULA. – David Dec 19 '16 at 13:33

In MATLAB the default direction of orientation of Planar array is y axis, which can be seen as

ula.getElementPosition

ans =

0         0         0         0         0         0         0         0         0         0
-22.4844  -17.4879  -12.4914   -7.4948   -2.4983    2.4983    7.4948   12.4914   17.4879   22.4844
0         0         0         0         0         0         0         0         0         0


which makes your planar array graphical representation of antenna elements as beam pattern to be The Pattern is identical in front and back of the planar array, so this bring us to the region of operations for your case either front of array or back of array.

In case you want to shift the beam to 30 degrees then you can not distinguish between +30 and +150 degrees because as per matlab definition of azimuth angle which can be found here we are looking at identical beams in different regions as can be seen from the figure below I have tried to change the azimuth angles as per MATLAB convention +30 and -30 degrees and the signal is now separable. So you can work from +90 to -90 degree for Region 1

The modified code

clear;
clc;
close all;
t = 0:0.001:0.3;                % Time, sampling frequency is 1kHz
s = zeros(size(t));
s = s(:);                       % Signal in column vector
s(201:205) = s(201:205) + 1;    % Define the pulse
s_2 = zeros(size(t));
s_2 = s_2(:);                       % Signal in column vector
s_2(41:47) = s_2(41:47) + 1;    % Define the pulse
figure(1)
plot(t,s, t, s_2);
title('Pulse');xlabel('Time (s)');ylabel('Amplitude (V)');
carrierFreq = 30e6;
wavelength = physconst('LightSpeed')/carrierFreq;
ula = phased.ULA('NumElements',10,'ElementSpacing',wavelength/2);
ula.Element.FrequencyRange = [90e5 110e6];
inputAngle = [30; 0];
x = collectPlaneWave(ula,s,inputAngle,carrierFreq);
inputAngleTwo = [-30; 0];
x2 = collectPlaneWave(ula,s_2,inputAngleTwo,carrierFreq);
rs = RandStream.create('mt19937ar','Seed',2008);
noisePwr = .5;   % noise power
noise = sqrt(noisePwr/2)*(randn(rs,size(x))+1i*randn(rs,size(x)));
rxSignal = x + x2 + noise;
figure()
subplot(211);
plot(t,abs(rxSignal(:,1)));axis tight;
title('Pulse at Antenna 1');xlabel('Time (s)');ylabel('Magnitude (V)');
subplot(212);
plot(t,abs(rxSignal(:,2)));axis tight;
title('Pulse at Antenna 2');xlabel('Time (s)');ylabel('Magnitude (V)');
psbeamformerOne = phased.PhaseShiftBeamformer('SensorArray',ula,...
'OperatingFrequency',carrierFreq,'Direction',inputAngle,...
'WeightsOutputPort', true);
[yCbf,w] = step(psbeamformerOne, rxSignal);
figure()
subplot(2,1,1)
plot(t,abs(yCbf)); axis tight;
title(['Output of Phase Shift Beamformer when beam is at: +30 degrees' ] );
xlabel('Time (s)');ylabel('Magnitude (V)');

clear yCbf w;
psbeamformerTwo = phased.PhaseShiftBeamformer('SensorArray',ula,...
'OperatingFrequency',carrierFreq,'Direction',inputAngleTwo,...
'WeightsOutputPort', true);
[yCbf,w] = step(psbeamformerTwo, rxSignal);
subplot(2,1,2)
plot(t,abs(yCbf)); axis tight;
title(['Output of Phase Shift Beamformer when beam is at: -30 degrees' ] );
xlabel('Time (s)');ylabel('Magnitude (V)');


Result: Now the two signals are separable