-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfmcwBeamsteeringDemo.m
131 lines (101 loc) · 4.07 KB
/
fmcwBeamsteeringDemo.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
% This script demonstrates how to control the Phaser for beamforming
% purposes when the system is configured as a radar.
%
% % Setup:
%
% Connect the Vivaldi antenna to Phaser SMA Out2. Place the Vivaldi antenna
% in the field of view of the Phaser and point it at the Phaser.
%
% Notes:
%
% Run this script to generate a plot of the array factor when the transmit
% antenna is pointed towards the array. The received signal amplitude is
% highest when the receive beam is steered towards the transmit antenna.
% The first time this script is run, the data collection may not occur
% properly.
%
% Before performing beamforming, the Phaser analog and digital channels
% must be calibrated for phase and amplitude errors.
%
% Copyright 2023 The MathWorks, Inc.
%% Before doing any beamsteering, we need to calculate calibration weights for the antenna.
% Change this value to true if we need to calculate calibration
% weights. This only needs to be run once. The setup for calibration is
% different than the rest of the script. The HB100 needs to be placed at
% boresight for this function to work properly.
clear;
needsCalibration = false;
if needsCalibration
generateCalibrationWeights();
end
%% Clear workspace and load calibration weights
clear; close all;
% This will only work if the generateCalibrationWeights() function has been
% run in the prior section. If you get an error, run the
% generateCalibrationWeights function.
calibrationweights = loadCalibrationWeights();
%% First, setup the system similarly to fmcwDemo.m
% Carrier frequency
fc = 10e9;
lambda = physconst("LightSpeed")/fc;
% Put some requirements on the system
maxRange = 10;
rangeResolution = 1/3;
maxSpeed = 5;
speedResolution = 1/2;
% Determine some parameter values
rampbandwidth = ceil(rangeres2bw(rangeResolution)/1e6)*1e6;
fmaxdop = speed2dop(2*maxSpeed,lambda);
prf = 2*fmaxdop;
nPulses = ceil(2*maxSpeed/speedResolution);
tpulse = ceil((1/prf)*1e3)*1e-3;
tsweep = getFMCWSweepTime(tpulse,tpulse);
sweepslope = rampbandwidth / tsweep;
fmaxbeat = sweepslope * range2time(maxRange);
fs = max(ceil(2*fmaxbeat),520834);
% See fmcw demo for these setup steps
[rx,tx,bf,bf_TDD,model] = setupFMCWRadar(fc,fs,tpulse,tsweep,nPulses,rampbandwidth);
% Clear cache
rx();
% Use constant amplitude baseband transmit data
amp = 0.9 * 2^15;
txWaveform = amp*ones(rx.SamplesPerFrame,2);
%% Next, steer from -90:90 while transmitting, plot the amplitude at each angle
analogPosition = model.Subarray.getElementPosition() / lambda;
digitalPosition = model.getSubarrayPosition() / lambda;
steerangles = -90:5:90;
amplitudes = zeros(numel(steerangles),1);
for azangle = steerangles
% Get the beamforming weights for the current azimuth angle
angle = [azangle;0];
analogWeights = cbfweights(analogPosition,angle);
digitalWeights = cbfweights(digitalPosition,angle);
% Normalize the beamforming weights
analogWeights = analogWeights / max(abs(analogWeights));
digitalWeights = digitalWeights / max(abs(digitalWeights));
% Adjust the beamforming weights with the calibration weights
analogWeights = analogWeightsCalAdjustment(analogWeights,calibrationweights.AnalogWeights);
digitalWeights = digitalWeightsCalAdjustment(digitalWeights,calibrationweights.DigitalWeights);
% Setup the analog beamformers
setAnalogBfWeights(bf,analogWeights);
% capture data
data = captureTransmitWaveform(txWaveform,rx,tx,bf);
% Apply digital weights
data = data * conj(digitalWeights);
% Arrange data into pulses
data = arrangePulseData(data,rx,bf,bf_TDD);
% Save the average amplitude of all of the pulses for the current angle
amplitudes(azangle==steerangles) = calculateAmplitude(data);
end
% Plot the captures amplitude data
ax = axes(figure);
plot(steerangles,amplitudes);
xlabel("Steer Angle"); ylabel("Signal Amplitude");
% Disable TDD Trigger so we can operate in Receive only mode
disableTddTrigger(bf_TDD)
%% Helpers
function amp = calculateAmplitude(data)
% Calculate the average amplitude for a dataset by just taking the mean
% of the magnitude
amp = mean(mean(abs(data)));
end