diff --git a/RTX class/Antenna.m b/RTX class/Antenna.m index 29eb040f924a00363ff78bf7ec7a560632608dee..4000ab2d21a889ac258291e09bcaea9fdb3d82bd 100644 --- a/RTX class/Antenna.m +++ b/RTX class/Antenna.m @@ -3,7 +3,8 @@ classdef Antenna position Vect; amplitude = ones(1, 1000); phase = zeros(1, 1000); - integral = zeros(1, 1000); + integral; + end methods @@ -29,11 +30,12 @@ classdef Antenna function rays = generateRaysB(obj, nRay) phi = linspace(0, 2*pi, length(obj.amplitude)); - randArray = rand(1, nRay); + dPhi = 2*pi/length(obj.amplitude); + randArray = rand(2, nRay); for j=1:nRay - minval = min(abs(obj.integral - randArray(j)*obj.integral(end))); - phiIndex = find(abs(obj.integral - randArray(j)*obj.integral(end)) == minval, 1, 'last'); - phiRay = phi(phiIndex); + minval = min(abs(obj.integral - randArray(1,j)*obj.integral(end))); + phiIndex = find(abs(obj.integral - randArray(1,j)*obj.integral(end)) == minval, 1, 'last'); + phiRay = phi(phiIndex)+dPhi/2*(2*randArray(2,j)-1); rays(j) = Ray(obj.position, [cos(phiRay), sin(phiRay)], exp(1i*obj.phase(phiIndex))); end end @@ -53,7 +55,7 @@ classdef Antenna n = size(phi, 2); rpower = zeros(1, n-1); rphase = zeros(1, n-1); - data_phi = linspace(0, 2*pi, size(obj.amplitude, 2)); + data_phi = linspace(0, 2*pi, size(obj.amplitude, 2)); if (n > size(data_phi,2)/2) % Interpolate when characteristics have fewer samples new_data_phi = linspace(0, 2*pi, 2*n); @@ -63,6 +65,7 @@ classdef Antenna end dphi = 2 * pi / size(obj.amplitude, 2); + totalPower = sum(obj.amplitude)*dphi; for j = 1:n-1 [~, start_index] = min(abs(data_phi - phi(j))); [~, stop_index] = min(abs(data_phi - phi(j+1))); @@ -74,8 +77,7 @@ classdef Antenna end rphase(j) = obj.phase(ceil((start_index + stop_index) / 2)); end - complex_amplitudes = rpower.*exp(1i*rphase); + complex_amplitudes = rpower.*exp(1i*rphase)/totalPower; end end end -