diff --git a/RTX class/RTX.m b/RTX class/RTX.m new file mode 100644 index 0000000000000000000000000000000000000000..0f5e4faef7f7115c91762390e7c22049f029da62 --- /dev/null +++ b/RTX class/RTX.m @@ -0,0 +1,112 @@ +classdef RTX < handle + %RTX Summary of this class goes here + % Detailed explanation goes here + + properties + reflectors Barrier; + aperture Aperture; + antenna Antenna = Antenna(Vect(1, 0)); + wavelength double = 1; + nRay = 10000; + rays Ray; + traces Trace; + histogram; + field; + end + + methods + function obj = RTX(reflectors, aperture, antenna, wavelength, nRay) + obj.reflectors = reflectors; + obj.aperture = aperture; + if nargin > 4 + obj.nRay = nRay; + end + if nargin > 3 + obj.wavelength = wavelength; + end + if nargin > 2 + obj.antenna = antenna; + end + end + + function traces = trace(obj, maxCollision) + if nargin == 1 + maxCollision = 5; + end + progBar = waitbar(0,'Generating rays...','Name','Tracing rays...',... + 'CreateCancelBtn','setappdata(gcbf,''canceling'',1)'); + setappdata(progBar,'canceling',0); + stepSize = obj.nRay/100; + obj.rays = obj.antenna.generateRaysB(obj.nRay); + for j = 1:obj.nRay + if getappdata(progBar,'canceling') + break; + end + if mod(j, stepSize) == 0 + waitbar(j/obj.nRay,progBar,sprintf('Tracing rays... [%0.1f%%]',j/obj.nRay*100)); + end + obj.traces(j) = Trace(j, obj.rays(j), obj.wavelength, [obj.reflectors obj.aperture], maxCollision); + end + obj.histogram = obj.aperture.getCollisionHistogram(); + traces = obj.traces; + delete(progBar); + end + + function field = calculateFarField(obj, nTheta, nFi) + if nargin < 2 + nTheta = 1000; + end + if nargin < 3 + nFi = 500; + end + if isempty(obj.traces) + obj.trace(); + end + obj.field = FarField.CalculateFarField(nTheta, nFi, obj.aperture.size, obj.wavelength, obj.histogram); + field = obj.field; + end + + function plotApertureField(obj) + if isempty(obj.histogram) + obj.trace(); + end + figure; + x = linspace(-obj.aperture.size/2, obj.aperture.size/2, length(obj.histogram)); + plot(x, abs(obj.histogram)); + title("Apertúrán áthaladó sugarak eloszlása"); + xlabel("Pozíció"); + ylabel("Sugarak száma"); + end + + function plotFarField(obj) + if isempty(obj.traces) + obj.trace(); + end + if isempty(obj.field) + obj.calculateFarField(); + end + y = abs(obj.field); + y = y/max(y); + plot(20*log10(y)); + end + + function plotSetup(obj) + if isempty(obj.traces) + return + end + figure; + xlim([0 4]); + ylim([-4 4]); + title("Szimulációs elrendezés"); + obj.antenna.plot_antenna(); + hold on; + for k = 1:length(obj.reflectors) + obj.reflectors(k).plot_self(); + end + for k = 1:obj.nRay + obj.traces(k).plot_trace(5); + end + hold off; + end + end +end diff --git a/RTX class/rtx_test.m b/RTX class/rtx_test.m new file mode 100644 index 0000000000000000000000000000000000000000..444bfb5c2f812b530ef29834081ecb89e45c4f13 --- /dev/null +++ b/RTX class/rtx_test.m @@ -0,0 +1,13 @@ +clear +close all + +reflectors = [PlaneReflector([2 0], 2), ParabolaReflector([0 0], 4, 3)]; +aperture = BalazsAperture([3 0], 20, 1000); +antenna = Antenna(Vect(1,0), [ones(1,125), zeros(1,750), ones(1,125)], zeros(1,1000)); +wavelength = 3e8/1e9; +nRay = 1000; + +rtx = RTX(reflectors, aperture, antenna, wavelength, nRay); +rtx.trace(); +rtx.plotApertureField(); +rtx.plotFarField();