diff --git a/RTX class/Antenna.m b/RTX class/Antenna.m index 4000ab2d21a889ac258291e09bcaea9fdb3d82bd..da794f5bcf26ff19058bfbab803ac3f1704c0107 100644 --- a/RTX class/Antenna.m +++ b/RTX class/Antenna.m @@ -27,6 +27,16 @@ classdef Antenna rays(k) = Ray(obj.position, [cos(phi(k)), sin(phi(k))], complexAmplitudes(k-1)); end end + + function rays = generateRaysDet(obj) + phi = linspace(0,2*pi, length(obj.amplitude)); + idx = find(obj.amplitude > 0); + phi = phi(idx); + complexAmplitudes = obj.amplitude(idx); + for k = 1:length(phi) + rays(k) = Ray(obj.position, [cos(phi(k)), sin(phi(k))], complexAmplitudes(k)); + end + end function rays = generateRaysB(obj, nRay) phi = linspace(0, 2*pi, length(obj.amplitude)); @@ -36,7 +46,7 @@ classdef Antenna 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))); + rays(j) = Ray(obj.position, [cos(phiRay), sin(phiRay)], 1/nRay*exp(1i*obj.phase(phiIndex))); end end diff --git a/RTX class/BalazsAperture.m b/RTX class/BalazsAperture.m index 4499a12b301e249790e90b2f3abd2fae973bca7f..f7470050ef82960b2da8df2643ce52d0179b2fd8 100644 --- a/RTX class/BalazsAperture.m +++ b/RTX class/BalazsAperture.m @@ -14,14 +14,14 @@ classdef BalazsAperture < Aperture end function histogram = getCollisionHistogram(obj) %change from original - histogram = obj.collisions; + histogram = obj.collisions / (obj.size / obj.nslice); end function post_collide(obj, col, trace) if (col.collided) %change from original i = floor(obj.nslice*(col.pos.y-obj.center.y+obj.size/2)/obj.size) + 1; phase = angle(trace.complexAmplitude) + 2*pi * mod(trace.length, trace.wavelength)/trace.wavelength; - obj.collisions(i) = obj.collisions(i) + exp(1i*phase); + obj.collisions(i) = obj.collisions(i) + abs(trace.complexAmplitude)*exp(1i*phase); end end @@ -46,6 +46,22 @@ classdef BalazsAperture < Aperture yticks([-pi, -3*pi/4, -pi/2, -pi/4, 0, pi/4, pi/2, 3*pi/4, pi]); yticklabels({'-\pi', '', '-^{1}/_{2}\pi', '',... '0', '', '^{1}/_{2}\pi', '', '\pi'}); - end + end + + function directivity = calcDirectivity(obj, wavelength) + histogram = obj.getCollisionHistogram(); + E = histogram(floor(end/2):end); + r = linspace(0, obj.size/2, length(E)); + dr = r(2)-r(1); + num = abs(2*pi*sum(r.*E)*dr)^2; + den = sum(abs(2*pi*sum(r.*E)*dr).^2); + directivity = 4*pi*num/den/wavelength^2; + end + + function sumE = calcSumE(obj, wavelength) + E = obj.getCollisionHistogram(); + dr = obj.size/length(E); + sumE = sum(abs(E)); + end end end diff --git a/RTX class/RTX.m b/RTX class/RTX.m index bcc70b6a5f353ba78042698de9120cffab244174..b8ec48394f28c150af2819beea8d7c1f77f94e57 100644 --- a/RTX class/RTX.m +++ b/RTX class/RTX.m @@ -28,7 +28,7 @@ classdef RTX < handle end end - function traces = trace(obj, maxCollision) + function traces = trace(obj, maxCollision, deterministic) if nargin == 1 maxCollision = 5; end @@ -36,7 +36,9 @@ classdef RTX < handle 'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); setappdata(progBar,'canceling',0); stepSize = obj.nRay/100; - if isa(obj.aperture, 'SegmentedAperture') + if nargin > 2 && deterministic + obj.rays = obj.antenna.generateRaysDet(); + elseif isa(obj.aperture, 'SegmentedAperture') obj.rays = obj.antenna.generateRays(linspace(0,2*pi, obj.nRay)); else obj.rays = obj.antenna.generateRaysB(obj.nRay); @@ -97,8 +99,9 @@ classdef RTX < handle xlim([0 4]); ylim([-4 4]); title("Szimulációs elrendezés"); - obj.antenna.plot_antenna(); hold on; + obj.antenna.plot_antenna(); + obj.aperture.plot_self(); for k = 1:length(obj.reflectors) obj.reflectors(k).plot_self(); end @@ -106,6 +109,18 @@ classdef RTX < handle obj.traces(k).plot_trace(5); end hold off; - end + xlabel('X'); + ylabel('Y'); + end + + function directivity = calcDirectivity(obj) + directivity = obj.aperture.calcDirectivity(obj.wavelength); + end + + + function sumE = calcSumE(obj) + sumE = obj.aperture.calcSumE(obj.wavelength); + end + end end diff --git a/RTX class/SegmentedAperture.m b/RTX class/SegmentedAperture.m index 2ce94b37e3b852d1c8799f4113eee0657dea303c..66a011a7be4656bf3c7b8206953967bbb4b4b207 100644 --- a/RTX class/SegmentedAperture.m +++ b/RTX class/SegmentedAperture.m @@ -56,8 +56,28 @@ classdef SegmentedAperture < Aperture yticks([-pi, -3*pi/4, -pi/2, -pi/4, 0, pi/4, pi/2, 3*pi/4, pi]); yticklabels({'-\pi', '', '-^{1}/_{2}\pi', '',... '0', '', '^{1}/_{2}\pi', '', '\pi'}); + end + + function directivity = calcDirectivity(obj, wavelength) + [hist, starts, ends] = obj.getCollisionHistogram(); + first = max(find(starts > 0, 1), find(ends > 0, 1)); + starts = starts(first:end); + ends = ends(first:end); + E = hist(first:end); - + r = starts; + dr = ends-starts; + num = abs(2*pi*sum(r.*E.*dr))^2; + den = sum(abs(2*pi*sum(r.*E.*dr)).^2); + directivity = 4*pi*num/den/wavelength^2; + end + + function sumE = calcSumE(obj, wavelength) + [hist, starts, ends] = obj.getCollisionHistogram(); + E = hist; + + dr = ends-starts; + sumE = sum(abs(E.*dr)); end end end diff --git a/RTX class/rtx_basics.m b/RTX class/rtx_basics.m new file mode 100644 index 0000000000000000000000000000000000000000..2fa70d00c9427bd2dac5722bf8561665077dffb2 --- /dev/null +++ b/RTX class/rtx_basics.m @@ -0,0 +1,18 @@ +reflectors = [PlaneReflector([2 0], 2), ParabolaReflector([0 0], 4, 3)]; +aperture = SegmentedAperture([2.1 0], 5); + antenna = Antenna(Vect(1,0), [zeros(1,20), 1, zeros(1,130), 1, zeros(1,200), 1 zeros(1,550) 1, zeros(1,80)], zeros(1,10000)); +%antenna = Antenna(Vect(1,0), [ones(1,20)], zeros(1,20)); +wavelength = 3e8/1e9; +nRay = 4; +nRay2 = 20; + +rtx = RTX(reflectors, aperture, antenna, wavelength, nRay); +rtx.trace(5, true); +rtx.plotSetup(); +% rtx.plotApertureField(); +% rtx.plotFarField(); +% rtx2 = RTX(reflectors, aperture2, antenna, wavelength, nRay2); +% rtx2.trace(); +% rtx2.plotSetup(); +% rtx2.plotApertureField(); +% rtx2.plotFarField(); diff --git a/RTX class/rtx_test.m b/RTX class/rtx_test.m index 0cdb737af5de89450c7e15911ba1cc0ed4c9fabd..1a6f1007859b28aa692c67089e0f39fcf6199780 100644 --- a/RTX class/rtx_test.m +++ b/RTX class/rtx_test.m @@ -1,12 +1,12 @@ clear close all -reflectors = [PlaneReflector([2 0], 2), ParabolaReflector([0 0], 4, 3)]; +reflectors = [PlaneReflector([2 0], 0), ParabolaReflector([0 0], 4, 3)]; %reflectors = [PlaneReflector([-1 1], 0)]; -aperture = BalazsAperture([3 0], 20, 1000); -aperture2 = SegmentedAperture([3 0], 20); +aperture = BalazsAperture([2.0001 0], 20, 1000); +aperture2 = SegmentedAperture([2.0001 0], 20); antenna = Antenna(Vect(1,0), [ones(1,1250), zeros(1,7500), ones(1,1250)], zeros(1,10000)); -% antenna = Antenna(Vect(1,0), ones(1,10000), zeros(1,10000)); +%antenna = Antenna(Vect(1,0), ones(1,10000), zeros(1,10000)); wavelength = 3e8/1e9; nRay = 10000; nRay2 = 2000; @@ -19,3 +19,6 @@ rtx2 = RTX(reflectors, aperture2, antenna, wavelength, nRay2); rtx2.trace(); rtx2.plotApertureField(); rtx2.plotFarField(); + +dir = rtx.calcDirectivity(); +