-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmitRec2F.m
116 lines (80 loc) · 2.85 KB
/
EmitRec2F.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
function [ F ] = EmitRec2F( Emitters, Receivers )
%EMITREC2F Compute the F matrix from emitter and receiver data.
%
% Emitter and receiver data are stored in struct arrays.
% Extract the position and orientation vectors from the HTMs
%% Extract the arrays with position and orientation vectors for emitters and receivers
% Input:
%
% - Emitters: an array of Emitters struct
% - Receivers: an array of Receivers struct
n_Emitters = numel(Emitters);
% Extract the HTMs from the struct array
HTM_E = [ Emitters.HTM ];
% and reshape in a 3-D array
HTM_E = reshape(HTM_E,4,4,n_Emitters);
% p_E holds the position vectors of the emitters
%
% One of the dimensions is superfluous. Remove it with squeeze()
p_E = squeeze(HTM_E(1:3,4,:));
% n_E holds the orientation vectors of the emitters
n_E = squeeze(HTM_E(1:3,3,:));
n_Receivers = numel(Receivers);
% Extract the HTMs from the structure array:
HTM_R = [ Receivers.HTM ];
% and reshape in a 3-D array
HTM_R = reshape(HTM_R,4,4,n_Receivers);
% Get the position vectors for receivers
p_R = squeeze(HTM_R(1:3,4,:));
% n_R holds the orientation vectors of the receivers
n_R = squeeze(HTM_R(1:3,3,:));
%% Compute the distance matrix
% Matrix with the receivers position
%
% The position vector of receivers should be replicated along the columns
% (3rd coord of the 3D matrix).
Mp_R = repmat(p_R,[1 1 n_Emitters]);
% Matrix with the receivers orientation
%
% The orientation vector of receivers should be replicated along the columns
% (3rd coord of the 3D matrix).
Mn_R = repmat(n_R,[1 1 n_Emitters]);
% Matrix with the emitters position
%
% The position vector of emitters should be replicated along the lines
% (2nd coord of the 3D matrix).
Mp_E = repmat(p_E,[1 1 n_Receivers]);
Mp_E = permute(Mp_E, [1 3 2]);
% Matrix with the emitters orientation
%
% The orientation vector of emitters should be replicated along the lines
% (2nd coord of the 3D matrix).
Mn_E = repmat(n_E,[1 1 n_Receivers]);
Mn_E = permute(Mn_E, [1 3 2]);
% Compute the difference matrix
% Delta(1:3,i,j) is the vector from the i-th receiver to the j-th emitter
Delta = Mp_E - Mp_R;
% Compute the matrix with the distances
% Dist(i,j) contains the distance from the i-th receiver to the j-th
% emitter
DistSquared = dot(Delta,Delta);
Dist = sqrt(DistSquared);
% u is the matrix with the versors of the directions from Receivers to
% Emitters
%
% u(:,i,j) contains the versor of the direction from the i-th receiver to
% the j-th emitter
DistRep = repmat(Dist,[3 1 1]);
u = Delta ./ DistRep;
%% Compute the terms for the final result
% Mm is the matrix with the m_j terms for the exponent of the Lambertian
% model
mv = [ Emitters.m ];
Mm = repmat(mv,[n_Receivers 1]);
F2 = squeeze(dot(Mn_E,-u)).^Mm;
F3 = squeeze(dot(Mn_R,u));
F4 = 1./squeeze(DistSquared);
Psiv = [ Receivers.Psi ]';
McPsi = cos(repmat(Psiv,[1 n_Emitters ]));
F = (F3 > McPsi).*F2.*F3.*F4;
end