diff --git a/@rfSensor/RSS.m b/@rfSensor/RSS.m index db0fcaf..605e287 100644 --- a/@rfSensor/RSS.m +++ b/@rfSensor/RSS.m @@ -7,10 +7,8 @@ function value = RSS(obj, d, t) arguments (Output) value (:, 1) double end - - 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); + assert(size(d, 1) == size(t, 1), "Mismatch in number of distances (%d) and tilts (%d) provided", size(d, 1), size(t, 1)); + % RSS (dBm) = TX Power (dBm) + Antenna Gain (dB) - Path Loss (dB) + value = obj.P_TX_dBm + obj.antennaGain(t) - obj.pathLoss(d); end \ No newline at end of file diff --git a/@rfSensor/computePointToPoints.m b/@rfSensor/computePointToPoints.m new file mode 100644 index 0000000..1a4e46e --- /dev/null +++ b/@rfSensor/computePointToPoints.m @@ -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 \ No newline at end of file diff --git a/@rfSensor/initialize.m b/@rfSensor/initialize.m index 20c3f87..be8dda6 100644 --- a/@rfSensor/initialize.m +++ b/@rfSensor/initialize.m @@ -9,8 +9,12 @@ function obj = initialize(obj, txPower, bandwidth, centerFreq) obj (1, 1) {mustBeA(obj, "rfSensor")} end - obj.P_TX = txPower; - obj.BW = bandwidth; - obj.f_c = centerFreq; - + % Provided values + obj.P_TX = txPower; % Transmit power (W) + 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 \ No newline at end of file diff --git a/@rfSensor/pathLoss.m b/@rfSensor/pathLoss.m index 69f51d9..08198d0 100644 --- a/@rfSensor/pathLoss.m +++ b/@rfSensor/pathLoss.m @@ -7,6 +7,7 @@ function L_FSPL_dB = pathLoss(obj, d) L_FSPL_dB (:, 1) double end + % Free Space Path Loss (dB) L_FSPL_dB = 20*log10(d) + 20*log10(obj.f_c) + 20*log10((4*pi)/obj.c); end diff --git a/@rfSensor/plotParameters.m b/@rfSensor/plotParameters.m index 1a39138..3d008a4 100644 --- a/@rfSensor/plotParameters.m +++ b/@rfSensor/plotParameters.m @@ -9,17 +9,13 @@ function f = plotParameters(obj) % Distance and tilt sample points d = [0.01, 0.1, 0.25, 0.5, 0.75, 1:1:100]; t = zeros(size(d)); - t = -90:1:90; % Sample RSS function by distances, tilts r_x = obj.RSS(d', t'); % Sample SINR (SNR) function by distances, tilts % using SINR method with no other transmitters defined is equivalent to SNR - s_x = NaN(size(r_x)); - 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 + s_x = obj.sensorPerformance(d, t); % don't define other sensors % Plot resultant sigmoid curves f = figure; diff --git a/@rfSensor/rfSensor.m b/@rfSensor/rfSensor.m index 9759fd0..9d56285 100644 --- a/@rfSensor/rfSensor.m +++ b/@rfSensor/rfSensor.m @@ -8,12 +8,16 @@ classdef rfSensor P_TX = NaN; % Transmit power (Watts) BW = NaN; % Bandwidth (Hz) f_c = NaN; % Center frequency (Hz) + % Values computed at initialization + P_TX_dBm = NaN; % Transmit power (dBm) + N = NaN; % Thermal noise end methods (Access = public) [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 [f] = plotParameters(obj); % debug, plot sensor response as a function of distance and tilt angle + [d, t] = computePointToPoints(obj, agentPos, targetPos); end methods (Access = private) x = RSS(obj, d, t); % Received signal strength (function of distance and tilt angle) diff --git a/@rfSensor/sensorPerformance.m b/@rfSensor/sensorPerformance.m index c88d7d5..be6d329 100644 --- a/@rfSensor/sensorPerformance.m +++ b/@rfSensor/sensorPerformance.m @@ -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) obj (1, 1) {mustBeA(obj, "rfSensor")}; - agentPos (1, 3) double; - targetPos (1, 3) double; - otherSensors (:, 1) cell = {}; - otherSensorsPos (:, 3) double = NaN(0, 3); + d (:, 1) double; + t(:, 1) double; + d_other (:, :) double = []; + t_other (:, :) double = []; + otherSensors (1, :) cell = {}; end arguments (Output) SINR (:, 1) double; 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)); - - d = vecnorm(agentPos - targetPos, 2, 2); % distance from sensor to target - d_other = NaN(size(otherSensors)); - - 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)); + 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)); + 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)); + 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)); % Performance is measured as SINR for this sensor - S = 10^(0.1 * obj.RSS(d, t)); % Signal - N = obj.k_B * obj.T_0 * obj.BW; % Thermal noise - I = 0; % Interference from other agents - for ii = 1:size(otherSensors, 1) - 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))); + S = 10 .^ (0.1 * obj.RSS(d, t)); % Signal + I = zeros(size(d)); % Interference from other agents + for ii = 1:size(otherSensors, 2) + I = I + 10 .^ (0.1 * otherSensors{ii}.RSS(d_other(:, ii), t_other(:, ii))); end - SINR = 10*log10(S/(I + N)); + + SINR = 10*log10(S ./ (I + obj.N)); end \ No newline at end of file diff --git a/test/test_rfSensor.m b/test/test_rfSensor.m index c6495a1..621002e 100644 --- a/test/test_rfSensor.m +++ b/test/test_rfSensor.m @@ -29,7 +29,6 @@ classdef test_rfSensor < matlab.unittest.TestCase f_c = 2e9; % Center frequency (Hz) tc.testClass = tc.testClass.initialize(P_TX, BW, f_c); - - + end end end \ No newline at end of file