Skip to content
Snippets Groups Projects
Commit 319c9049 authored by ftomi's avatar ftomi
Browse files

E

parent bcc0a100
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,16 @@ classdef Antenna
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));
dPhi = 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
......
......@@ -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
......@@ -47,5 +47,21 @@ classdef BalazsAperture < Aperture
yticklabels({'-\pi', '', '-^{1}/_{2}\pi', '',...
'0', '', '^{1}/_{2}\pi', '', '\pi'});
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
......@@ -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;
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
......@@ -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
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();
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));
wavelength = 3e8/1e9;
......@@ -19,3 +19,6 @@ rtx2 = RTX(reflectors, aperture2, antenna, wavelength, nRay2);
rtx2.trace();
rtx2.plotApertureField();
rtx2.plotFarField();
dir = rtx.calcDirectivity();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment