-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDoaEstimation.m
264 lines (256 loc) · 14.8 KB
/
DoaEstimation.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
function [doa, spacialSpectrum] = DoaEstimation(sysPara, hArray, waveformRx, waveformPilot)
% /*!
% * @brief This function estimates the DOA of rx waveform according to the doa method.
% * @details .
% * @param[out] doa, 2xK doulbe. DOA of rx waveform. Each column represents one target/interfernence. Direction in degree, [azimuth; elevation].
% The azimuth angle must be between ¨C180 and 180 degrees, and the elevation angle must be between ¨C90 and 90 degrees. K is the
% number of incoming waves.
% * @param[out] spacialSpectrum, is a 3D matrix representing the magnitude of the estimated 2-D spatial spectrum for each target.
% first dimension equals to the number of elevation angles specified in ElevationScanAngles
% second dimension equals to the number of azimuth angles specified in AzimuthScanAngles.
% third dimension coresponds to the target. (note: some method does not distinguish targets, therefore the third dimension is 1.)
% * @param[in] sysPara, 1x1 struct, which contains the following field:
% see get used field for detail.
% * @param[in] hArray, 1x1 antenna array system object.
% * @param[in] waveformRx, NxM complex vector. received waveform. N is the number of samples(snaps), M is the number of channel
% * @param[in] waveformPilot, NxL complex vector. pilot waveform. N is the number of samples(snaps), L is the number of pilots
% from targets. This parameter is optional in some beamforming method.
% * @pre .
% * @bug Null
% * @warning Null
% * @author Collus Wang
% * @version 1.0
% * @date 2017.06.27.
% * @copyright Collus Wang all rights reserved.
% * @remark { revision history: V1.0, 2017.05.25. Collus Wang, first draft }
% * @remark { revision history: V1.1, 2017.07.12. Collus Wang, change output parameter spacialSpectrum from 2D to 3D. }
% * @remark { revision history: V1.2, 2017.07.19. Wayne Zang, differentiate common MUSIC and anti-interference MUSIC algorithm. }
% * @remark { revision history: V1.3, 2017.10.18. Wayne Zang, MUSIC method peak search optimization and support DoaEstiMaxNumSig feature. }
% */
%% Get used field
DoaEstimator = sysPara.DoaEstimator;
FreqCenter = sysPara.FreqCenter;
AzimuthScanAngles = sysPara.AzimuthScanAngles;
ElevationScanAngles = sysPara.ElevationScanAngles;
NumTarget = sysPara.NumTarget;
LenWaveform = sysPara.LenWaveform;
DOAIncludeElementResponse = sysPara.DOAIncludeElementResponse;
DoaEstiMaxNumSig = sysPara.DoaEstiMaxNumSig;
%% Flags
GlobalDebugPlot = sysPara.GlobalDebugPlot;
FlagDebugPlot = true && GlobalDebugPlot;
figureStartNum = 6000;
%% process
switch lower(DoaEstimator)
case 'toolboxmusicestimator2d'
spacialSpectrum = zeros(length(ElevationScanAngles), length(AzimuthScanAngles), 1); % this method does not distinguish targets, therefore the third dimension is 1.
LenRS = 512; % RS length
if LenWaveform < LenRS, error('Waveform length < RS length!'); end % check length
idxRS = (1:LenRS) + 0; % RS indices
hDoaEstimator = phased.BeamscanEstimator2D('SensorArray',hArray,...
'OperatingFrequency',FreqCenter,...
'DOAOutputPort',true,...
'NumSignals',NumTarget,...
'AzimuthScanAngles',AzimuthScanAngles.',...
'ElevationScanAngles',ElevationScanAngles.');
[spacialSpectrum(:,:,1), doa] = step(hDoaEstimator, waveformRx(idxRS,:));
% sort DOA azimuth angles in ascending order
[~,idxTmp] = sort(doa(1,:), 'ascend');
doa = doa(:,idxTmp);
if FlagDebugPlot
figure(figureStartNum); clf;
plotSpectrum(hDoaEstimator)
if isvector(spacialSpectrum(:,:,1)) % 1D DOA, plot the estimated DOA on spectrum
TargetAngle = sysPara.TargetAngle;
InterferenceAngle = sysPara.InterferenceAngle;
SwitchInterence = sysPara.SwitchInterence;
hold on
for idxTmp = 1:size(doa,2)
plot([TargetAngle(1,idxTmp), TargetAngle(1,idxTmp)], [min(mag2db(spacialSpectrum)), mag2db(spacialSpectrum(AzimuthScanAngles==TargetAngle(1,idxTmp)))], 'b-' )
if SwitchInterence
plot([InterferenceAngle(1,idxTmp), InterferenceAngle(1,idxTmp)], [min(mag2db(spacialSpectrum)), mag2db(spacialSpectrum(AzimuthScanAngles==InterferenceAngle(1,idxTmp)))], 'r--' )
end
plot([doa(1,idxTmp), doa(1,idxTmp)], [min(mag2db(spacialSpectrum)), mag2db(spacialSpectrum(AzimuthScanAngles==doa(1,idxTmp)))], 'b-o' )
end
legend('Spatial Spectrum', 'Target', 'Interference', 'DOA', 'Location', 'best')
end
end
case 'cbf'
spacialSpectrum = zeros(length(ElevationScanAngles), length(AzimuthScanAngles), NumTarget);
LenRS = 512; % RS length
if LenWaveform < LenRS, error('Waveform length < RS length!'); end % check length
idxRS = (1:LenRS) + 0; % RS indices
Pxs = waveformRx(idxRS,:).'*conj(waveformPilot(idxRS,:))/LenRS; % cross-correlation vector
hSteeringVector = phased.SteeringVector('SensorArray', hArray,...
'PropagationSpeed', physconst('LightSpeed'),...
'IncludeElementResponse', DOAIncludeElementResponse,...
'NumPhaseShifterBits', 0 ... 'EnablePolarization', false ...
);
elevationScanVector = ones(size(AzimuthScanAngles))*ElevationScanAngles;
angleScanVector = [AzimuthScanAngles, elevationScanVector];
steeringVector = step(hSteeringVector, FreqCenter, angleScanVector.');
steeringVector = steeringVector*diag(rms(steeringVector).^-1);
angleMatchVector = abs(steeringVector'*Pxs);
[~, idxPeak] = max(angleMatchVector);
doa = angleScanVector(idxPeak, :).';
spacialSpectrum(1,:,:) = angleMatchVector;
if FlagDebugPlot
TargetAngle = sysPara.TargetAngle;
for idxTarget = 1:NumTarget
figure(figureStartNum + idxTarget);
hold off;
plot(AzimuthScanAngles, mag2db(spacialSpectrum(1,:,idxTarget)), 'b-');
hold on;
plot([TargetAngle(1,idxTarget), TargetAngle(1,idxTarget)],...
[min(mag2db(spacialSpectrum(1,:,idxTarget))),...
mag2db(spacialSpectrum(1,(TargetAngle(1,idxTarget) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,idxTarget))], 'b-');
plot([doa(1,idxTarget), doa(1,idxTarget)],...
[min(mag2db(spacialSpectrum(1,:,idxTarget))),...
mag2db(spacialSpectrum(1,(doa(1,idxTarget) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,idxTarget))], 'bo-');
grid on;
axis([min(AzimuthScanAngles), max(AzimuthScanAngles), min(mag2db(spacialSpectrum(1,:,idxTarget))), max(mag2db(spacialSpectrum(1,:,idxTarget)))]);
title(['Target ', num2str(idxTarget), ': Common Beamform Spatial Spectrum at Elevation 0 Degree']);
xlabel('Azimuth Angle(degree)');
ylabel('Power(dB)');
legend('Spatial Spectrum', 'Target', 'DOA');
end
end
case 'music'
spacialSpectrum = zeros(length(ElevationScanAngles), length(AzimuthScanAngles), NumTarget);
LenRS = 512; % RS length
if LenWaveform < LenRS, error('Waveform length < RS length!'); end % check length
idxRS = (1:LenRS) + 0; % RS indices
hSteeringVector = phased.SteeringVector('SensorArray', hArray,...
'PropagationSpeed', physconst('LightSpeed'),...
'IncludeElementResponse', DOAIncludeElementResponse,...
'NumPhaseShifterBits', 0 ... 'EnablePolarization', false ...
);
elevationScanVector = ones(size(AzimuthScanAngles))*ElevationScanAngles;
angleScanVector = [AzimuthScanAngles, elevationScanVector];
steeringVector = step(hSteeringVector, FreqCenter, angleScanVector.');
steeringVector = steeringVector*diag(rms(steeringVector).^-1);
Rxx = waveformRx(idxRS,:).'*conj(waveformRx(idxRS,:))/LenRS;
% eigen value decomposition
[eigV, eigD] = eig(Rxx, 'vector');
[~, idx] = sort(eigD, 'ascend');
eigD = eigD(idx);
eigV = eigV(:,idx);
% find out the Number of signal.
SigThd = 0.8*sum(eigD); % assume the signals power should exceed certurn percentage of the total power.
NumCh = length(eigD);
pwrSum = 0;
NumSig = NumCh-1; % at least one column for noise space
for idx = 1:NumCh-1
pwrSum = pwrSum + eigD(NumCh-idx+1);
if pwrSum>SigThd
NumSig = idx;
break;
end
end
% noise space construction
Vnoise = eigV(:, 1:NumCh-NumSig );
Rnn = Vnoise*Vnoise';
Pmusic = 1./abs(sum((steeringVector'*Rnn.*steeringVector.').').');
if DoaEstiMaxNumSig ==1
[~,idxDoa] = max(Pmusic);
else
processSpectrum = Pmusic.'/max(Pmusic);
processSpectrum = pow2db(processSpectrum);
processSpectrumExpand = [processSpectrum(2), processSpectrum, processSpectrum(end-1)]; % expand the spectrum so that findpeaks can return peaks at the boundary.
% peak para.
minPeakHeight = -15;
minPeakProminence = .5;
minPeakDistance = 1/(AzimuthScanAngles(2)-AzimuthScanAngles(1)); % degrees / reselution
% find peaks
[~, idxDoa] = findpeaks(processSpectrumExpand, 'NPeaks', min([DoaEstiMaxNumSig,NumSig]), 'MinPeakProminence', minPeakProminence, 'MinPeakHeight', minPeakHeight, 'MinPeakDistance', minPeakDistance);
idxDoa = idxDoa - 1; % index of processSpectrum and processSpectrumExpand differs 1 point
% if max is not in the peak list, add max
[~,idxMax] = max(processSpectrum);
if ~sum(idxDoa == idxMax)
idxDoa = [idxMax, idxDoa];
end
end
doaSelect = angleScanVector(idxDoa, :).';
% make sure number of DOAs is the same as NumberTarget so that it can be compared in main.
if NumTarget > size(doaSelect, 2)
doa = [doaSelect,repmat([NaN;NaN], 1, NumTarget - size(doaSelect, 2))];
else
doa = doaSelect(:,1:NumTarget);
end
spacialSpectrum(:,:,1) = Pmusic;
if FlagDebugPlot
TargetAngle = sysPara.TargetAngle;
figure(figureStartNum);
hold off;
plot(AzimuthScanAngles, mag2db(spacialSpectrum(1,:,1)), 'b-');
hold on;
for idxSig = 1:size(doaSelect, 2)
plot([doaSelect(1,idxSig), doaSelect(1,idxSig)],...
[min(mag2db(spacialSpectrum(1,:,1))),...
mag2db(spacialSpectrum(1,(doaSelect(1,idxSig) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,1))], 'bo-');
end
for idxTarget = 1:NumTarget
plot([TargetAngle(1,idxTarget), TargetAngle(1,idxTarget)],...
[min(mag2db(spacialSpectrum(1,:,1))),...
mag2db(spacialSpectrum(1,(TargetAngle(1,idxTarget) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,1))], 'b-');
grid on;
axis([min(AzimuthScanAngles), max(AzimuthScanAngles), min(mag2db(spacialSpectrum(1,:,1))), max(mag2db(spacialSpectrum(1,:,1)))]);
title(['Target ', num2str(idxTarget), ': MUSIC Spatial Spectrum at Elevation 0 Degree']);
xlabel('Azimuth Angle(degree)');
ylabel('Power(dB)');
legend('Spatial Spectrum', 'Target', 'DOA');
end
end
case 'antiintermusic'
spacialSpectrum = zeros(length(ElevationScanAngles), length(AzimuthScanAngles), NumTarget);
LenRS = 512; % RS length
if LenWaveform < LenRS, error('Waveform length < RS length!'); end % check length
idxRS = (1:LenRS) + 0; % RS indices
hSteeringVector = phased.SteeringVector('SensorArray', hArray,...
'PropagationSpeed', physconst('LightSpeed'),...
'IncludeElementResponse', DOAIncludeElementResponse,...
'NumPhaseShifterBits', 0 ... 'EnablePolarization', false ...
);
elevationScanVector = ones(size(AzimuthScanAngles))*ElevationScanAngles;
angleScanVector = [AzimuthScanAngles, elevationScanVector];
steeringVector = step(hSteeringVector, FreqCenter, angleScanVector.');
steeringVector = steeringVector*diag(rms(steeringVector).^-1);
Pxs = waveformRx(idxRS,:).'*conj(waveformPilot(idxRS,:))/LenRS; % cross-correlation vector
doa = zeros(2, size(Pxs, 2));
for idxTarget = 1:size(Pxs, 2)
Rxx = Pxs(:, idxTarget)*Pxs(:, idxTarget)';
[eigV, eigD] = eig(Rxx);
eigD = diag(eigD);
[~, idxMaxEig] = max(eigD);
unitI = eye(size(Rxx, 1));
unitI(idxMaxEig, idxMaxEig) = 0;
noiseSpace = eigV*unitI*eigV';
Pmusic = 1./abs(sum((steeringVector'*noiseSpace.*steeringVector.').').');
[~, idxPeak] = max(Pmusic);
doa(:, idxTarget) = angleScanVector(idxPeak, :).';
spacialSpectrum(1,:,idxTarget) = Pmusic;
end
if FlagDebugPlot
TargetAngle = sysPara.TargetAngle;
for idxTarget = 1:NumTarget
figure(figureStartNum + idxTarget);
hold off;
plot(AzimuthScanAngles, mag2db(spacialSpectrum(1,:,idxTarget)), 'b-');
hold on;
plot([TargetAngle(1,idxTarget), TargetAngle(1,idxTarget)],...
[min(mag2db(spacialSpectrum(1,:,idxTarget))),...
mag2db(spacialSpectrum(1,(TargetAngle(1,idxTarget) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,idxTarget))], 'b-');
plot([doa(1,idxTarget), doa(1,idxTarget)],...
[min(mag2db(spacialSpectrum(1,:,idxTarget))),...
mag2db(spacialSpectrum(1,(doa(1,idxTarget) - AzimuthScanAngles(1))/(AzimuthScanAngles(2) - AzimuthScanAngles(1)) + 1,idxTarget))], 'bo-');
grid on;
axis([min(AzimuthScanAngles), max(AzimuthScanAngles), min(mag2db(spacialSpectrum(1,:,idxTarget))), max(mag2db(spacialSpectrum(1,:,idxTarget)))]);
title(['Target ', num2str(idxTarget), ': Anti-Inter MUSIC Spatial Spectrum at Elevation 0 Degree']);
xlabel('Azimuth Angle(degree)');
ylabel('Power(dB)');
legend('Spatial Spectrum', 'Target', 'DOA');
end
end
otherwise
error('Unsupported DOA estimator.');
end