Skip to content
Snippets Groups Projects
Commit c4310bb3 authored by frey.balazs96's avatar frey.balazs96 :eggplant:
Browse files

Merge branch 'master' of https://git.sch.bme.hu/ftomi/antennahf

parents 5e73c8b9 c92ce86e
No related branches found
No related tags found
No related merge requests found
classdef Antenna
properties
amplitude = ones(1, 1000);
phase = ones(1, 1000);
phase = zeros(1, 1000);
position Vect;
end
methods
function obj = Antenna(amplitude ,phase)
function obj = Antenna(position, amplitude ,phase)
obj.position = position;
if nargin > 1
obj.amplitude = amplitude;
obj.phase = phase;
end
end
function [rays, complex_amplitudes] = generate_rays(obj, phi)
rays(size(phi, 2)) = Ray;
for k = 1:size(phi, 2)
rays(k) = Ray(obj.position, [cos(phi(k)), sin(phi(k))]);
end
complex_amplitudes = obj.get_complex_amplitudes(phi);
end
function plot_characteristics(obj)
phi = linspace(0,2*pi,1000);
polarplot(phi, obj.amplitude, phi, obj.phase);
end
function complex_amplitude = get_ray_data(obj, phi)
function plot_antenna(obj)
plot(obj.position.x, obj.position.y, 'kO', 'MarkerSize', 10);
end
end
methods(Access = protected)
function complex_amplitudes = get_complex_amplitudes(obj, phi)
n = size(phi, 2);
rpower = zeros(1, n-1);
rphase = zeros(1, n-1);
......@@ -25,8 +47,8 @@ classdef Antenna
dphi = 2 * pi / size(obj.amplitude, 2);
for j = 1:n-1
[m, start_index] = min(abs(data_phi - phi(j)));
[m, stop_index] = min(abs(data_phi - phi(j+1)));
[~, start_index] = min(abs(data_phi - phi(j)));
[~, stop_index] = min(abs(data_phi - phi(j+1)));
for k = start_index:stop_index
if j ~= 1 && k == start_index
continue;
......@@ -35,13 +57,7 @@ classdef Antenna
end
rphase(j) = obj.phase(ceil((start_index + stop_index) / 2));
end
complex_amplitude = rpower.*exp(1i*rphase);
end
function plot(obj)
phi = linspace(0,2*pi,1000);
polarplot(phi, obj.amplitude, phi, obj.phase);
complex_amplitudes = rpower.*exp(1i*rphase);
end
end
end
......@@ -10,39 +10,5 @@ classdef Ray
obj.dir = dir;
end
end
function t = trace(obj, barriers, maxCol)
t = Trace(obj);
ncol = 0;
for m = 1:maxCol
col = Collision;
col.collided = false;
dist = +Inf;
col_barrier = 1;
for k = 1:size(barriers,2)
c = barriers(k).collide(t.rays(ncol+1)); % get collision from the 'k'th barrier
if (c.collided)
d = Vect.abs(c.pos - obj.start);
if d < dist
dist = d;
col = c;
col_barrier = k;
end
end
end
if col.collided
ncol = ncol + 1;
next_ray = Ray(col.pos, col.reflDir);
t = t + next_ray;
barriers(col_barrier).post_collide(col);
if col.stop
t.trace_end();
%Nem tudom ez mire való: rays(m+1).dir = Vect;
break;
end
else
break;
end
end
end
end
end
classdef Trace < handle
properties
id;
wavelength;
rays Ray = [];
length = +inf;
init_phase = 0;
......@@ -8,20 +10,42 @@ classdef Trace < handle
end
methods
function obj = Trace(rays, init_phase)
if isvector(rays)
obj.rays = rays;
return
else
obj.rays(1) = rays;
end
if nargin == 2
function obj = Trace(id, init_ray, init_phase, wavelength, barriers, maxCol)
obj.id = id;
obj.rays(1) = init_ray;
obj.init_phase = init_phase;
obj.wavelength = wavelength;
ncol = 0;
for m = 1:maxCol
col = Collision;
col.collided = false;
dist = +Inf;
col_barrier = 1;
for k = 1:size(barriers,2)
c = barriers(k).collide(obj.rays(ncol+1)); % get collision from the 'k'th barrier
if (c.collided)
d = Vect.abs(c.pos - init_ray.start);
if d < dist
dist = d;
col = c;
col_barrier = k;
end
end
end
if col.collided
ncol = ncol + 1;
next_ray = Ray(col.pos, col.reflDir);
obj.rays(end+1) = next_ray;
barriers(col_barrier).post_collide(col);
if col.stop
obj.trace_end();
break;
end
else
break;
end
end
function p = plus(t,r)
p = Trace([t.rays r], t.init_phase);
end
function length = trace_end(obj)
......
......@@ -3,24 +3,22 @@ reflectors(end+1) = PlaneReflector([2 0], 2);
reflectors(end+1) = ParabolaReflector([0 0], 4, 3);
reflectors(end+1) = BalazsAperture([3 0], 20, 1000);
start = Vect(1, 0);
n_ray = 10000;
phi_start = -pi;%angle(1-1i);
phi_stop = pi;%angle(1+1i);
phi = linspace(phi_start, phi_stop, n_ray);
rays(n_ray) = Ray;
for k = 1:size(phi, 2)
rays(k) = Ray(start, [cos(phi(k)), sin(phi(k))]);
end
phi_start = -pi;
phi_stop = pi;
n = 1000;
wavelength = 3e8/1e9;
antenna = Antenna(Vect(1,0));
[rays, complex_amplitudes] = antenna.generate_rays(linspace(phi_start, phi_stop, n));
figure(1);
plot(0, 0);
hold on;
for k = 1:n_ray
t = rays(k).trace(reflectors, 5);
for k = 1:size(rays, 2)
t = Trace(k, rays(k), 0, wavelength, reflectors, 5);
%t.plot_trace();
end
plot(start.x, start.y, 'kO', 'MarkerSize', 10);
antenna.plot_antenna();
for k = 1:size(reflectors, 2)
reflectors(k).plot_self;
end
......@@ -37,4 +35,3 @@ plot(histogram);
%field = field/max(field);
%plot(20*log10(field));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment