From 096808c6489d3dc3b8f49a09573355b40e4c7145 Mon Sep 17 00:00:00 2001
From: lmaresz <lmaresz@sch.bme.hu>
Date: Mon, 15 Jun 2020 21:59:30 +0200
Subject: [PATCH] plot fix, sim_characteristics

---
 RTX class/FarField.m            |  7 ++-
 RTX class/RTX.m                 |  8 +--
 RTX class/SegmentedAperture.m   |  6 ++-
 RTX class/sim_characteristics.m | 92 +++++++++++++++++++++++++++++++++
 4 files changed, 106 insertions(+), 7 deletions(-)
 create mode 100644 RTX class/sim_characteristics.m

diff --git a/RTX class/FarField.m b/RTX class/FarField.m
index d4209e8..5d884c8 100644
--- a/RTX class/FarField.m	
+++ b/RTX class/FarField.m	
@@ -78,17 +78,20 @@ classdef FarField < handle
             delete(progressBar2)
         end
         
-        function plot(obj)
+        function [x, y] = plot(obj)
             if isempty(obj.field)
                 obj.calculate();
             end
             y = abs(obj.field);
             y = y/max(y);
-            plot(obj.theta*180/pi, 20*log10(y));
+            plot(obj.theta*180/pi, 20*log10(y), 'LineWidth', 1.5);
+            grid on;
             title("Távoltér");
             xlabel("\Theta [°]");
             ylabel("S_{rel} [dB]");
             ylim([-50 1]);
+            x = obj.theta*180/pi;
+            y = 20*log10(y);
         end
         
         function beamWidth = getBeamWidth(obj)
diff --git a/RTX class/RTX.m b/RTX class/RTX.m
index b8ec483..de98bdf 100644
--- a/RTX class/RTX.m	
+++ b/RTX class/RTX.m	
@@ -74,21 +74,21 @@ classdef RTX < handle
             field = obj.farField.calculate();
         end
         
-        function plotApertureField(obj)
+        function [x, y] = plotApertureField(obj)
            if isempty(obj.aperture.getCollisionHistogram())
                 obj.trace();
            end
-           obj.aperture.plotApertureField();
+           [x, y] = obj.aperture.plotApertureField();
         end
         
-        function plotFarField(obj)
+        function [x, y] = plotFarField(obj)
             if isempty(obj.aperture.getCollisionHistogram())
                 obj.trace();
             end
             if isempty(obj.farField)
                 obj.calculateFarField();
             end
-            obj.farField.plot()        
+            [x, y] = obj.farField.plot();      
         end       
         
         function plotSetup(obj)
diff --git a/RTX class/SegmentedAperture.m b/RTX class/SegmentedAperture.m
index 494bc8a..0dafcc8 100644
--- a/RTX class/SegmentedAperture.m	
+++ b/RTX class/SegmentedAperture.m	
@@ -36,7 +36,7 @@ classdef SegmentedAperture < Aperture
             xStop = [obj.segments.segs.posEnd];
         end
         
-        function plotApertureField(obj)
+        function [x, y] = plotApertureField(obj)
             [histogram,x1, x2] = obj.getCollisionHistogram();
             x1 = [-obj.size/2, x1, x1(end)];
             x2 = [x1(2), x2, obj.size/2];
@@ -46,6 +46,7 @@ classdef SegmentedAperture < Aperture
             
             subplot(2,1,1);
             plot(x(:), abs(h(:)), 'LineWidth', 1.5);
+            grid on;
             title("Apertúra megvilágítsáfüggvénye - amplitúdó");
             xlabel("r'");
             ylabel("|E(r')| [V/m]");
@@ -54,6 +55,7 @@ classdef SegmentedAperture < Aperture
             
             subplot(2,1,2);
             plot(x(:), angle(h(:)), 'LineWidth', 1.5);
+            grid on;
             title("Apertúra megvilágítsáfüggvénye - fázis");
             xlabel("r'");
             ylabel("argE(r') [rad]");
@@ -62,6 +64,8 @@ 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'});
+            x = x(:);
+            y = h(:);
         end
         
         function directivity = calcDirectivity(obj, wavelength)
diff --git a/RTX class/sim_characteristics.m b/RTX class/sim_characteristics.m
new file mode 100644
index 0000000..5a93b9e
--- /dev/null
+++ b/RTX class/sim_characteristics.m	
@@ -0,0 +1,92 @@
+clear
+close all
+
+antPhi = 360/180*pi;
+antPos = 1;%linspace(0.8, 1.2, 3);
+planeRefSize = 2;%linspace(1.8, 2.2, 5);
+parabSize = 4;
+lambda = 0.1;%[0.05 0.1 0.2 0.5 1];
+rtx = RTX.empty();
+
+reflectors = [PlaneReflector([2 0], planeRefSize), ParabolaReflector([0 0], parabSize, 3)];
+aperture1 = SegmentedAperture([2.0001 0], 20);
+aperture2 = SegmentedAperture([2.0001 0], 20);
+antenna1 = Antenna(Vect(antPos,0), [ones(1,125), zeros(1,750), ones(1,125)], zeros(1,1000));
+antenna2 = Antenna(Vect(antPos,0));
+nRay = 1000;
+
+rtx1 = RTX(reflectors, aperture1, antenna1, lambda, nRay);
+rtx1.trace();
+rtx1.calculateFarField();
+rtx2 = RTX(reflectors, aperture2, antenna2, lambda, nRay);
+rtx2.trace();
+rtx2.calculateFarField();
+
+%% Plot settings
+
+plot_width = 1200;
+h_width = plot_width * 0.55;
+height = 400;
+file_format = 'png';
+save_plot = 1;
+
+%% Sim_characteristics_aperture_field
+
+[x1, y1] = rtx1.plotApertureField();
+[x2, y2] = rtx2.plotApertureField();
+close all;
+
+figure(1)
+subplot(2,1,1);
+hold on;
+plot(x1, abs(y1), 'b', 'LineWidth', 1);
+plot(x2, abs(y2), 'r', 'LineWidth', 1);
+hold off
+grid on;
+xlabel("r'");
+ylabel("|E(r')| [V/m]");
+xlim([-5, 5]);
+title("Cassegrain antenna megvilágítási függvénye");
+legend('Ideális primer sugárzó', 'Izotróp primer sugárzó', 'Location', 'northeast', 'Orientation', 'vertical');
+
+subplot(2,1,2);
+hold on;
+plot(x1, angle(y1), 'b', 'LineWidth', 1);
+plot(x2, angle(y2), 'r', 'LineWidth', 1);
+hold off
+grid on;
+xlabel("r'");
+ylabel("argE(r') [rad]");
+xlim([-5, 5]);
+ylim([-pi, pi]);
+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'});
+legend('Ideális primer sugárzó', 'Izotróp primer sugárzó', 'Location', 'northeast', 'Orientation', 'vertical');
+
+set(gcf, 'position', [0 0 h_width height]);
+if save_plot
+    saveas(gcf,'Sim_characteristics_aperture_field',file_format);
+end
+
+%% Sim_characteristics_far_field
+
+[x1, y1] = rtx1.plotFarField();
+[x2, y2] = rtx2.plotFarField();
+close all;
+
+plot(x1, y1, 'b',...
+     x2, y2, 'r', 'LineWidth', 1.5);
+grid on;
+title("Cassegrain antenna távoltere");
+legend('Ideális primer sugárzó', 'Izotróp primer sugárzó', 'Location', 'northeast', 'Orientation', 'vertical');
+xlabel("\Theta [°]");
+ylabel("S_{rel} [dB]");
+ylim([-60 1]);
+xlim([-15 15]);
+
+set(gcf, 'position', [0 0 h_width height]);
+if save_plot
+    saveas(gcf,'Sim_characteristics_far_field',file_format);
+end
+
-- 
GitLab