close all
clear all
clc

Rh=10;
Th=10;
f=1e9;
c=3e8;
lam=c/f;
k=2*pi/lam;
hmax=100;
dz=lam/8;
dz_count=round(hmax/dz);

filter=(1+cos(-pi+2*pi/(dz_count):2*pi/(dz_count):pi))/2;
filter(1:round(length(filter)/2))=1;

D=500;
x=[0,100,200,300,400,500];
r=zeros(1,length(x)); E_0=zeros(1,dz_count); E_n=zeros(1,dz_count);
%%
%prvni vlnoplocha
r=vp(x(1),x(2),Th,0,0,dz_count,dz,hmax);
E_0=exp(-1j*k.*r)./r;
E_p=E_0; %pomocny vektor do ktereho se ukladaji mezivysledky
ddz=1:1:dz_count;
ddz=ddz*dz;
plot(ddz,20*log10(abs(E_0)))
hold on
xlabel('vyska nad terenem [m]');
ylabel('uroven vykonu v bode prijimace [dB]');
%%
%dalsi vlnoplochy

for ind=3:1:length(x)
    ind
    K=sqrt(k*x(ind-1)/(2*pi*1j*x(ind)*(x(ind)-x(ind-1))));
    for indd=1:1:dz_count
        r=vp(x(ind-1),x(ind),indd*dz,0,0,dz_count,dz,hmax);
        E_n(indd)=K*sum(E_p.*exp(-1j*k.*r))*dz;       
    end
    E_p=E_n.*filter;
    plot(ddz,20*log10(abs(E_n)))
end
hold off
%%
E_Th=abs(E_n(round(Rh/dz)))
E_Th_v=abs(exp(-1j*k*D)/D)




