forked from sdrangan/wirelesscomm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_bf.m
333 lines (261 loc) · 8.7 KB
/
demo_bf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
%% Demo: Visualizing and Analyzing Phased Arrays in MATLAB
% In this demo, we will illustrate some basic computations
% for phased arrays. In doing this demo, you will learn to:
%
% * Add beamforming gain to a link budget
% * Create and visualize simple antenna arrays
% * Compute steering vectors and array factors
% * Plot array patterns in 2D and 3D
% * Incorporate element gain into the array
%% SNR gain example with RX beamforming
% To begin we illustrate the gain in SNR, we consider the following
% simple example. The example shows that 8 antennas provides a 9 dB
% SNR gain.
% Parameters
dist = 1000; % distance (m)
fc = 28e9; % frequency
lambda = physconst('LightSpeed')/fc;
ptx = 23; % TX power
dirtx = 10; % TX and RX directivity in dBi
dirrx = 5;
Enoise = -170; % Noise energy (incl NF)
bw = 400e6; % Bandwidth
nantrx = 8; % Number of RX antennas
% SNR per antenna assuming free-space path loss
plomni = fspl(dist, lambda);
EsN0Ant = ptx - plomni - 10*log10(bw) - Enoise + dirtx + dirrx;
% SNR with MRC
EsN0MRC = EsN0Ant + 10*log10(nantrx);
fprintf(1,'SNR per ant: %7.2f\n', EsN0Ant);
fprintf(1,'SNR with MRC: %7.2f\n', EsN0MRC);
%% Uniform Linear Array
% We first define a simple uniform linear array
fc = 28e9; % frequency
lambda = physconst('LightSpeed')/fc;
dsep = 0.5*lambda; % element spacing
nant = 8; % Number of elements
arr = phased.ULA(nant,dsep);
% View the array
viewArray(ula,'Title','Uniform Linear Array (ULA)')
%% Plotting the array element positions manually
% We can also get the positions into an array
% Note we need the clf('reset') command to clear the figure
% from viewArray. The phased array toolbox plotting routines
% screw up all future plots.
elemPos = arr.getElementPosition();
clf('reset');
plot(elemPos(1,:), elemPos(2,:), 'o');
%% Computing the spatial signature
% To compute the spatial signature of an array, you can use
% the following command
% Create a steering vector object
sv = phased.SteeringVector('SensorArray',arr);
% Angles to compute the SVs
npts = 361;
az = linspace(-180,180,npts);
el = zeros(1,npts);
ang = [az; el];
% Matrix of steering vectors
% This is an nant x npts matrix in this case
u = sv(fc, ang);
% Plot of the real components
plot(az, real(u)');
grid on;
xlabel('Azimuth (deg)')
ylabel('Real spatial sig');
%% Uniform Planar Array
% We next look at a simple uniform planar array
% Construct a URA
nant = [4,8];
dsep = 0.5*lambda;
arr = phased.URA(nant,dsep,'ArrayNormal','x');
% Plot the array.
% You can also use, arr.viewArray()
elemPos = arr.getElementPosition();
clf('reset');
plot(elemPos(2,:), elemPos(3,:), 'o');
grid on;
xlabel('y');
ylabel('z');
%% Manually plotting the 2D array factor
% We now show how to plot the array factor
% Create the ULA
nant = 8; % Number of elements
arr = phased.ULA(nant,dsep);
% Create a steering vector object
sv = phased.SteeringVector('SensorArray',arr);
% Reference angles to plot the AF
azPlot = [0, 90];
nplot = length(azPlot);
for iplot = 1:nplot
% Get the SV for the beam direction.
% Note: You must call release method of the sv
% before each call since it expects the same size
% of the input
ang0 = [azPlot(iplot); 0];
sv.release();
u0 = sv(fc, ang0);
% Normalize the direction
u0 = u0 / norm(u0);
% Get the SV for the AoAs. Take el=0
npts = 1000;
az = linspace(-180,180,npts);
el = zeros(1,npts);
ang = [az; el];
sv.release();
u = sv(fc, ang);
% Compute the AF and plot it
AF = 10*log10( abs(sum(conj(u0).*u, 1)).^2 );
% Plot it
subplot(1,nplot,iplot);
plot(ang(1,:), AF, 'LineWidth', 2);
grid on;
ylim([-20,10]);
xlabel('Azimuth');
ylabel('AF (dBi)');
xlim([-180,180]);
titleStr = sprintf('theta0 = %d', azPlot(iplot));
title(titleStr);
end
%% Polar plot of array factor in 2D
% Create a steering vector object
sv = phased.SteeringVector('SensorArray',arr);
% Reference angles to plot the AF
azPlot = [0, 45, 90];
nplot = length(azPlot);
for iplot = 1:nplot
% Get the SV for the beam direction.
% Note: You must call release method of the sv
% before each call since it expects the same size
% of the input
ang0 = [azPlot(iplot); 0];
sv.release();
u0 = sv(fc, ang0);
% Normalize the direction
u0 = u0 / norm(u0);
% Get the SV for the AoAs. Take el=0
npts = 1000;
az = linspace(-180,180,npts);
el = zeros(1,npts);
ang = [az; el];
sv.release();
u = sv(fc, ang);
% Compute the AF and plot it
AF = 10*log10( abs(sum(conj(u0).*u, 1)).^2 );
% Polar plot
AFmin = -30;
subplot(1,nplot,iplot);
polarplot(deg2rad(az), max(AF, AFmin),'LineWidth', 2);
rlim([AFmin, 10]);
grid on;
titleStr = sprintf('theta0 = %d', azPlot(iplot));
title(titleStr);
end
%% Plotting the AF using the in-built function
% You can also plot the directivity of the array with MATLAB's built
% in tool. Note that the directivity will be differ from the AF by a
% constant since it is normalized to one. Also, you do not have as much
% flexibility in this plot
% Parameters
dsep = 0.5*lambda; % element spacing
nant = 8; % Number of elements
arr = phased.ULA(nant,dsep);
% Get the SV for the beam direction.
ang0 = [45; 0];
sv.release();
u0 = sv(fc, ang0);
% Plot the pattern
subplot(1,1,1);
arr.patternAzimuth(fc, 'Weights', u0);
%% Grating lobes
% When the antennas are spaced more than lambda/2, we see other
% lobes where the arry has high gain. These are called grating lobes
% To illustrate we take d = 2\lambda.
dsep = 2*lambda; % element spacing
nant = 8; % Number of elements
arr = phased.ULA(nant,dsep);
% Get the SV for the beam direction.
ang0 = [0; 0];
sv.release();
u0 = sv(fc, ang0);
arr.patternAzimuth(fc,'Weights', u0);
%% Plotting the 3D pattern
% We can use MATLAB's function to plot the directivity.
% Again, remember the directivity differs from the AF by a constant
% factor.
% Construct a URA
nant = [4,8];
dsep = 0.5*lambda;
arr = phased.URA(nant,dsep,'ArrayNormal','x');
% Compute the beamforming vector
sv = phased.SteeringVector('SensorArray',arr);
ang0 = [0; 0];
sv.release();
u0 = sv(fc, ang0);
u0 = u0 / norm(u0);
% We can plot the directivity in a 3D plot
arr.pattern(fc,'Weights', u0);
%%
% We can also plot a 2D plot at a particular elevation angle.
% This is called a "cut"
elPlot = [0 45];
arr.patternAzimuth(fc, elPlot, 'Weights', u0);
%% Adding the element gain
% The above arrays were all isotropic elements. In practice, each element
% itself has a pattern. This can be included easily in the phased array
% toolbox. As an example, we add a standard path element and plot the
% resulting pattern of the array. We see that the element reduces the gain
% in negative x direction and increases the gain in the positive x direction.
% Create the patch element
len = 0.49*lambda;
groundPlaneLen = lambda;
ant = patchMicrostrip(...
'Length', len, 'Width', 1.5*len, ...
'GroundPlaneLength', groundPlaneLen, ...
'GroundPlaneWidth', groundPlaneLen, ...
'Height', 0.01*lambda, ...
'FeedOffset', [0.25*len 0]);
% Tilt the element so that the maximum energy is in the x-axis
ant.Tilt = 90;
ant.TiltAxis = [0 1 0];
% Build the array including the element
nant = [4,8];
arr2 = phased.URA(nant,dsep,'ArrayNormal','x','Element',ant);
% Plot the pattern of the array with isotropic elements
subplot(2,1,1);
arr.pattern(fc);
% Plot the pattern of the array with patch elements
subplot(2,1,2);
arr2.pattern(fc);
%% Visualizing pattern multiplication
% The gain in the previous plot can be explained by *pattern
% multiplication*: In dB scale, the element gain adds to the array gain.
% To visualize this, we plot the element gain along with the array
% directivity with isotropic elements and with actual elements
% Get the element gain
elPlot = 0;
az = (-180:180);
dirElem = ant.patternAzimuth(fc, elPlot, 'Azimuth', az);
% Get the directivity with isotropic elements
sv = phased.SteeringVector('SensorArray',arr);
ang0 = [0; 0];
sv.release();
u0 = sv(fc, ang0);
u0 = u0 / norm(u0);
dirIso = arr.patternAzimuth(fc, elPlot, 'Weights', u0, 'Azimuth', az);
% Get the directivity with patch element
dirTotal = arr2.patternAzimuth(fc, elPlot, 'Weights', u0, 'Azimuth', az);
% Plot the element gain
clf('reset');
dirMin = -20;
subplot(1,2,1);
polarplot(deg2rad(az), max(dirElem, dirMin), 'Linewidth', 2);
rlim([dirMin, 12]);
title('Element gain (dBi)');
% Plot the array directivity
subplot(1,2,2);
dirPlot = max(dirMin, [dirIso dirTotal]);
polarplot(deg2rad(az), dirPlot, 'Linewidth', 2);
title('Array Directivity (dBi)');
legend('Isotropic', 'With element gain', 'Location', 'SouthEast');
rlim([dirMin, 25]);