refactoring for vectorization
This commit is contained in:
+3
-5
@@ -7,10 +7,8 @@ function value = RSS(obj, d, t)
|
|||||||
arguments (Output)
|
arguments (Output)
|
||||||
value (:, 1) double
|
value (:, 1) double
|
||||||
end
|
end
|
||||||
|
assert(size(d, 1) == size(t, 1), "Mismatch in number of distances (%d) and tilts (%d) provided", size(d, 1), size(t, 1));
|
||||||
rho_dBm = 10*log10(obj.P_TX/1e-3);
|
|
||||||
|
|
||||||
% RSS = TX Power + Antenna Gain - Path Loss
|
|
||||||
value = rho_dBm + obj.antennaGain(t) - obj.pathLoss(d);
|
|
||||||
|
|
||||||
|
% RSS (dBm) = TX Power (dBm) + Antenna Gain (dB) - Path Loss (dB)
|
||||||
|
value = obj.P_TX_dBm + obj.antennaGain(t) - obj.pathLoss(d);
|
||||||
end
|
end
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
function [d, t] = computePointToPoints(obj, agentPos, targetPos)
|
||||||
|
arguments (Input)
|
||||||
|
obj (1, 1) {mustBeA(obj, "rfSensor")};
|
||||||
|
agentPos (1, 3) double;
|
||||||
|
targetPos (:, 3) double;
|
||||||
|
end
|
||||||
|
arguments (Output)
|
||||||
|
d (:, 1) double;
|
||||||
|
t (:, 1) double;
|
||||||
|
end
|
||||||
|
|
||||||
|
% distance from sensor to target
|
||||||
|
d = vecnorm(agentPos - targetPos, 2, 2);
|
||||||
|
|
||||||
|
% distance from sensor nadir to target nadir (i.e. distance ignoring altitude)
|
||||||
|
x = vecnorm(agentPos(1:2) - targetPos(:, 1:2), 2, 2);
|
||||||
|
|
||||||
|
% tilt angle (degrees)
|
||||||
|
t = (180 - atan2d(x, targetPos(:, 3) - agentPos(3)));
|
||||||
|
|
||||||
|
end
|
||||||
@@ -9,8 +9,12 @@ function obj = initialize(obj, txPower, bandwidth, centerFreq)
|
|||||||
obj (1, 1) {mustBeA(obj, "rfSensor")}
|
obj (1, 1) {mustBeA(obj, "rfSensor")}
|
||||||
end
|
end
|
||||||
|
|
||||||
obj.P_TX = txPower;
|
% Provided values
|
||||||
obj.BW = bandwidth;
|
obj.P_TX = txPower; % Transmit power (W)
|
||||||
obj.f_c = centerFreq;
|
obj.BW = bandwidth; % Bandwidth (Hz)
|
||||||
|
obj.f_c = centerFreq; % Center frequency (Hz)
|
||||||
|
|
||||||
|
% Computed values
|
||||||
|
obj.P_TX_dBm = 10*log10(obj.P_TX/1e-3); % Transmit power in dBm
|
||||||
|
obj.N = obj.k_B * obj.T_0 * obj.BW; % Thermal noise
|
||||||
end
|
end
|
||||||
@@ -7,6 +7,7 @@ function L_FSPL_dB = pathLoss(obj, d)
|
|||||||
L_FSPL_dB (:, 1) double
|
L_FSPL_dB (:, 1) double
|
||||||
end
|
end
|
||||||
|
|
||||||
|
% Free Space Path Loss (dB)
|
||||||
L_FSPL_dB = 20*log10(d) + 20*log10(obj.f_c) + 20*log10((4*pi)/obj.c);
|
L_FSPL_dB = 20*log10(d) + 20*log10(obj.f_c) + 20*log10((4*pi)/obj.c);
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,17 +9,13 @@ function f = plotParameters(obj)
|
|||||||
% Distance and tilt sample points
|
% Distance and tilt sample points
|
||||||
d = [0.01, 0.1, 0.25, 0.5, 0.75, 1:1:100];
|
d = [0.01, 0.1, 0.25, 0.5, 0.75, 1:1:100];
|
||||||
t = zeros(size(d));
|
t = zeros(size(d));
|
||||||
t = -90:1:90;
|
|
||||||
|
|
||||||
% Sample RSS function by distances, tilts
|
% Sample RSS function by distances, tilts
|
||||||
r_x = obj.RSS(d', t');
|
r_x = obj.RSS(d', t');
|
||||||
|
|
||||||
% Sample SINR (SNR) function by distances, tilts
|
% Sample SINR (SNR) function by distances, tilts
|
||||||
% using SINR method with no other transmitters defined is equivalent to SNR
|
% using SINR method with no other transmitters defined is equivalent to SNR
|
||||||
s_x = NaN(size(r_x));
|
s_x = obj.sensorPerformance(d, t); % don't define other sensors
|
||||||
for ii = 1:size(s_x, 1)
|
|
||||||
s_x(ii) = obj.sensorPerformance([0, 0, d(ii)], zeros(1, 3)); % don't define other sensors
|
|
||||||
end
|
|
||||||
|
|
||||||
% Plot resultant sigmoid curves
|
% Plot resultant sigmoid curves
|
||||||
f = figure;
|
f = figure;
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ classdef rfSensor
|
|||||||
P_TX = NaN; % Transmit power (Watts)
|
P_TX = NaN; % Transmit power (Watts)
|
||||||
BW = NaN; % Bandwidth (Hz)
|
BW = NaN; % Bandwidth (Hz)
|
||||||
f_c = NaN; % Center frequency (Hz)
|
f_c = NaN; % Center frequency (Hz)
|
||||||
|
% Values computed at initialization
|
||||||
|
P_TX_dBm = NaN; % Transmit power (dBm)
|
||||||
|
N = NaN; % Thermal noise
|
||||||
end
|
end
|
||||||
|
|
||||||
methods (Access = public)
|
methods (Access = public)
|
||||||
[obj] = initialize(obj, txPower, bandwidth, centerFreq); % TODO initialize sensor, define parameters
|
[obj] = initialize(obj, txPower, bandwidth, centerFreq); % TODO initialize sensor, define parameters
|
||||||
[SINR] = sensorPerformance(obj, agentPos, agentPan, agentTilt, targetPos); % determine sensor performance for a given single sensor and target geometry
|
[SINR] = sensorPerformance(obj, agentPos, agentPan, agentTilt, targetPos); % determine sensor performance for a given single sensor and target geometry
|
||||||
[f] = plotParameters(obj); % debug, plot sensor response as a function of distance and tilt angle
|
[f] = plotParameters(obj); % debug, plot sensor response as a function of distance and tilt angle
|
||||||
|
[d, t] = computePointToPoints(obj, agentPos, targetPos);
|
||||||
end
|
end
|
||||||
methods (Access = private)
|
methods (Access = private)
|
||||||
x = RSS(obj, d, t); % Received signal strength (function of distance and tilt angle)
|
x = RSS(obj, d, t); % Received signal strength (function of distance and tilt angle)
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
function SINR = sensorPerformance(obj, agentPos, targetPos, otherSensors, otherSensorsPos)
|
function SINR = sensorPerformance(obj, d, t, d_other, t_other, otherSensors)
|
||||||
arguments (Input)
|
arguments (Input)
|
||||||
obj (1, 1) {mustBeA(obj, "rfSensor")};
|
obj (1, 1) {mustBeA(obj, "rfSensor")};
|
||||||
agentPos (1, 3) double;
|
d (:, 1) double;
|
||||||
targetPos (1, 3) double;
|
t(:, 1) double;
|
||||||
otherSensors (:, 1) cell = {};
|
d_other (:, :) double = [];
|
||||||
otherSensorsPos (:, 3) double = NaN(0, 3);
|
t_other (:, :) double = [];
|
||||||
|
otherSensors (1, :) cell = {};
|
||||||
end
|
end
|
||||||
arguments (Output)
|
arguments (Output)
|
||||||
SINR (:, 1) double;
|
SINR (:, 1) double;
|
||||||
end
|
end
|
||||||
assert(size(otherSensors, 1) == size(otherSensorsPos, 1), "Mismatch in length of other sensors (%d) and their positions (%d)", size(otherSensors, 1), size(otherSensorsPos, 1));
|
assert(size(d, 1) == size(t, 1), "Mismatch in number of distance (%d) and angle (%d) pairs provided", size(d, 1), size(t, 1));
|
||||||
|
assert(size(d_other, 1) == size(t_other, 1), "Mismatch in number of distances (%d) and tilts (%d) provided to other sensors", size(t, 1), size(t_other, 1));
|
||||||
d = vecnorm(agentPos - targetPos, 2, 2); % distance from sensor to target
|
assert(size(d_other, 2) == size(t_other, 2), "Mismatch in number of other sensors given distances (%d) and tilts (%d)", size(d_other, 1), size(t_other, 1));
|
||||||
d_other = NaN(size(otherSensors));
|
assert(size(otherSensors, 2) == size(d_other, 2), "Mismatch in number of distances from other sensors (%d) and number of other sensors (%d) provided", size(d_other, 2), size(otherSensors, 2));
|
||||||
|
|
||||||
x = vecnorm(agentPos(1:2) - targetPos(1, 1:2), 2, 2); % distance from sensor nadir to target nadir (i.e. distance ignoring height difference)
|
|
||||||
x_other = NaN(size(otherSensors));
|
|
||||||
|
|
||||||
t = (180 - atan2d(x, targetPos(1, 3) - agentPos(3))); % degrees
|
|
||||||
t_other = NaN(size(otherSensors));
|
|
||||||
|
|
||||||
% Performance is measured as SINR for this sensor
|
% Performance is measured as SINR for this sensor
|
||||||
S = 10^(0.1 * obj.RSS(d, t)); % Signal
|
S = 10 .^ (0.1 * obj.RSS(d, t)); % Signal
|
||||||
N = obj.k_B * obj.T_0 * obj.BW; % Thermal noise
|
I = zeros(size(d)); % Interference from other agents
|
||||||
I = 0; % Interference from other agents
|
for ii = 1:size(otherSensors, 2)
|
||||||
for ii = 1:size(otherSensors, 1)
|
I = I + 10 .^ (0.1 * otherSensors{ii}.RSS(d_other(:, ii), t_other(:, ii)));
|
||||||
d_other(ii, 1) = vecnorm(otherSensorsPos(ii, 1:3) - targetPos, 2, 2);
|
|
||||||
|
|
||||||
x_other(ii, 1) = vecnorm(otherSensorsPos(ii, 3) - targetPos(1, 1:2), 2, 2);
|
|
||||||
t_other(ii, 1) = (180 - atan2d(x_other(ii, 1), targetPos(1, 3) - otherSensorsPos(ii, 3)));
|
|
||||||
|
|
||||||
I = I + 10 ^ (0.1 * otherSensors.RSS(otherSensors{ii}, d_other(ii), t_other(ii)));
|
|
||||||
end
|
end
|
||||||
SINR = 10*log10(S/(I + N));
|
|
||||||
|
SINR = 10*log10(S ./ (I + obj.N));
|
||||||
end
|
end
|
||||||
@@ -29,7 +29,6 @@ classdef test_rfSensor < matlab.unittest.TestCase
|
|||||||
f_c = 2e9; % Center frequency (Hz)
|
f_c = 2e9; % Center frequency (Hz)
|
||||||
|
|
||||||
tc.testClass = tc.testClass.initialize(P_TX, BW, f_c);
|
tc.testClass = tc.testClass.initialize(P_TX, BW, f_c);
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user