-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdoaEstimation.m
222 lines (178 loc) · 7.73 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
% Direction of Arrival Estimation, i.e., Spatial Spectrum Estimation
% MUSIC: Multiple Signal Classification
clc;
clear;
delete(findall(0, 'Type', 'figure'));
% STEP a: Simulating the Narrowband Sources %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
p = 100; % Number of time snapshots
fs = 10^7; % Sampling frequency
fc = 10^6; % Center frequency of narrowband sources
M = 10; % Number of array elements, i.e., sensors or antennas
N = 5; % Number of sources
sVar = 1; % Variance of the amplitude of the sources
% p snapshots of N narrowband sources with random amplitude of mean zero
% and covariance 1
s = sqrt(sVar)*randn(N, p).*exp(1i*(2*pi*fc*repmat([1:p]/fs, N, 1)));
% STEP a: Simulating the Narrowband Sources %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% STEP b: Mixing the sources and getting the sensor signals %%%%%%%%%%%%%%
doa = [20; 50; 85; 110; 145]; %DOAs
cSpeed = 3*10^8 ; % Speed of light
dist = 150; % Sensors (i.e., antennas) spacing in meters
% Constructing the Steering matrix
A = zeros(M, N);
for k = 1:N
A(:, k) = exp(-1i*2*pi*fc*dist*cosd(doa(k))*(1/cSpeed)*[0:M-1]');
end
noiseCoeff = 1; % Variance of added noise
x = A*s + sqrt(noiseCoeff)*randn(M, p); % Sensor signals
% STEP b: Mixing the sources and getting the sensor signals %%%%%%%%%%%%%%
% STEP c: Estimating the covariance matrix of the sensor array %%%%%%%%%%%
R = (x*x')/p; % Empirical covariance of the antenna data
% STEP c: Estimating the covariance matrix of the sensor array %%%%%%%%%%%
% STEP d: Finding the noise subspace and estimating the DOAs %%%%%%%%%%%%%
[V, D] = eig(R);
noiseSub = V(:, 1:M-N); % Noise subspace of R
theta = 0:1:180; %Peak search
a = zeros(M, length(theta));
res = zeros(length(theta), 1);
for i = 1:length(theta)
a(:, i) = exp(-1i*2*pi*fc*dist*cosd(i)*(1/cSpeed)*[0:M-1]');
res(i, 1) = 1/(norm(a(:, i)'*noiseSub).^2);
end
[resSorted, orgInd] = sort(res, 'descend');
DOAs = orgInd(1:N, 1);
% STEP d: Finding the noise subspace and estimating the DOAs %%%%%%%%%%%%%
%%
clc;
clear;
delete(findall(0, 'Type', 'figure'));
% STEP e: Repeating the experiment for different parameters %%%%%%%%%%%%%%
DOAs1 = [];
DOAs2 = [];
DOAs3 = [];
p = 100; % Number of time snapshots
fs = 10^7; % Sampling frequency
fc = 10^6 ; % Center frequency of narrowband sources
M = 10; % Number of array elements, i.e., sensors or antennas
N = 5; % Number of sources
doa = [20; 50; 85; 110; 145]; %DOAs
cSpeed = 3*10^8 ; % Speed of light
%%% PART 1, repeating for different noise variances
dist = 150;
sVar = 1;
s = sqrt(sVar)*randn(N, p).*exp(1i*(2*pi*fc*repmat([1:p]/fs, N, 1)));
A = zeros(M, N);
for k = 1:N
A(:, k) = exp(-1i*2*pi*fc*dist*cosd(doa(k))*(1/cSpeed)*[0:M-1]');
end
noiseV = [1, 5, 10, 20, 35, 50];
for i = 1:size(noiseV, 2)
noiseCoeff = noiseV(i); % Variance of added noise
x = A*s + sqrt(noiseCoeff)*randn(M, p); % Sensor signals
R = (x*x')/p; % Empirical covariance of the antenna data
[V, D] = eig(R);
noiseSub = V(:, 1:M-N); % Noise subspace of R
theta = 0:1:180; %Peak search
a = zeros(M, length(theta));
res = zeros(length(theta), 1);
for j = 1:length(theta)
a(:, j) = exp(-1i*2*pi*fc*dist*cosd(j)*(1/cSpeed)*[0:M-1]');
res(j, 1) = 1/(norm(a(:, j)'*noiseSub).^2);
end
[resSorted, orgInd] = sort(res, 'descend');
DOAs1 = [DOAs1, orgInd(1:N, 1)];
figure;
plot(res);
xlabel('Angle (deg)');
ylabel('1/Norm^2');
title ('Estimation of DOAs over the different noise variances')
grid;
% According to the results, we can infer that there is a negative correlation
% between the noise variance and the accuracy of estimation, i.e., the latter
% decreases as we increase the former. This is because the peaks are became
% less sharp and some fake peaks are generated in some cases.
% If we start from the largest eigen value to the smallest one in the
% corresponding diagonal matrix and calculate the difference between
% i-th and (i-1)-th eigen values, we observe that for low noise cases,
% there are approximately M-N larger eigen values which among them, the
% difference between i-th and (i-1)-th one is much greater than the
% corresponding figure for the remaining eigen values. Hence we can
% conclude that M-N is the number of sources.
% This function can give an estimation of the number of sources
disp (['Estimated number of sources (noise variance = ', ...
num2str(noiseCoeff),'): ', num2str(numSources(D))]);
end
%%
%%% PART 2, repeating for different inter-spacing between antennas
noiseCoeff = 5; % Variance of added noise
sVar = 1;
s = sqrt(sVar)*randn(N, p).*exp(1i*(2*pi*fc*repmat([1:p]/fs, N, 1)));
distV = [50, 100, 150, 200, 253]; % Differenet spacings in meters
for i = 1:size(distV, 2)
dist = distV(i);
A = zeros(M, N);
for k = 1:N
A(:, k) = exp(-1i*2*pi*fc*dist*cosd(doa(k))*(1/cSpeed)*[0:M-1]');
end
x = A*s + sqrt(noiseCoeff)*randn(M, p); % Sensor signals
R = (x*x')/p; % Empirical covariance of the antenna data
[V, D] = eig(R);
noiseSub = V(:, 1:M-N); % Noise subspace of R
theta = 0:1:180; %Peak search
a = zeros(M, length(theta));
res = zeros(length(theta), 1);
for j = 1:length(theta)
a(:, j) = exp(-1i*2*pi*fc*dist*cosd(j)*(1/cSpeed)*[0:M-1]');
res(j, 1) = 1/(norm(a(:, j)'*noiseSub).^2);
end
[resSorted, orgInd] = sort(res, 'descend');
DOAs2 = [DOAs2, orgInd(1:N, 1)];
figure;
plot(res);
xlabel('Angle (deg)');
ylabel('1/Norm^2');
title ('Estimation of DOAs over the different inter-spacing between antennas')
grid;
% According to the results, we can observe that (very) large or (very)
% small spacing between antennas can result in low accuracy of
% estimation due to the generation of small and/or fake peaks. Thus,
% there is an optimum value for inter-spacing between antennas and can
% be calculated by doing a sweep on its corresponding variable.
end
%%% PART 3, repeating for different variances of the amplitude of sources
noiseCoeff = 5; % Variance of added noise
dist = 150;
sVarV = [0.01, 0.1, 1, 5, 10]; % Differenet amplitude variances
for i = 1:size(sVarV, 2)
sVar = sVarV(i); % Variance of the amplitude of the sources
s = sqrt(sVar)*randn(N, p).*exp(1i*(2*pi*fc*repmat([1:p]/fs, N, 1)));
A = zeros(M, N);
for k = 1:N
A(:, k) = exp(-1i*2*pi*fc*dist*cosd(doa(k))*(1/cSpeed)*[0:M-1]');
end
x = A*s + sqrt(noiseCoeff)*randn(M, p); % Sensor signals
R = (x*x')/p; % Empirical covariance of the antenna data
[V, D] = eig(R);
noiseSub = V(:, 1:M-N); % Noise subspace of R
theta = 0:1:180; %Peak search
a = zeros(M, length(theta));
res = zeros(length(theta), 1);
for j = 1:length(theta)
a(:, j) = exp(-1i*2*pi*fc*dist*cosd(j)*(1/cSpeed)*[0:M-1]');
res(j, 1) = 1/(norm(a(:, j)'*noiseSub).^2);
end
[resSorted, orgInd] = sort(res, 'descend');
DOAs3 = [DOAs3, orgInd(1:N, 1)];
figure;
plot(res);
xlabel('Angle (deg)');
ylabel('1/Norm^2');
title ('Estimation of DOAs over the differenet sources amplitude variances')
grid;
% According to the results, we can infer that there is a positive
% correlation between the the variance of the amplitude of the sources
% and the accuracy of estimation, i.e., the latter increases as we
% increase the former. This is because the peaks are became sharper and
% larger, and also fake peaks are prevented.
end
% STEP e: Repeating the experiment for different parameters %%%%%%%%%%%%%%