function  [location_ver, location_hor] = get_loc(r);
% clear all;
% close all;

h1 = 0.8;
%r = 3;
P = 100;

n = 1;
for freq = 30e6:1e6:1000e6

    i = 1;
    for h2 = 1:0.01:4

         r1 = sqrt((h2-h1)^2 + r^2);
         r2 = sqrt((h1+h2)^2 + r^2);
         del_r = r2 - r1;

         lam = 3e8/freq;
         k = 2*pi/lam;

         E1(i) = (sqrt(30*P)/r1);
         E2(i) = (sqrt(30*P)/r2);

         Ev(i) = abs( E1(i) + E2(i)*exp(j*k*del_r));
         Eh(i) = abs( E1(i) - E2(i)*exp(j*k*del_r));
         
         i = i + 1;
    end        
  
        [pks_ver,locs_ver] = findpeaks(Ev);
        [pks_hor,locs_hor] = findpeaks(Eh);

        loc_ver = (locs_ver/length(Ev))*3+1;
        loc_hor = (locs_hor/length(Eh))*3+1;

        if (isempty(pks_ver) | (pks_ver < max(Ev)))
            if Ev(1) == max(Ev)
                  pks_ver = max(Ev);
                  loc_ver = 1;       

            elseif Ev(i-1) == max(Ev)
                  pks_ver = max(Ev);
                  loc_ver = 4;       
            end
        end
        
        if (isempty(pks_hor) | (pks_hor < max(Eh)))
            if Eh(1) == max(Eh)
                  pks_hor = max(Eh);
                  loc_hor = 1;   

            elseif Eh(i-1) == max(Eh)
                  pks_hor = max(Eh);
                  loc_hor = 4;       
            end  
            
         end
              
            location_ver(n) = loc_ver(1);
            location_hor(n) = loc_hor(1);
            
            n = n + 1;
end

%     Xplot = 30e6:10e6:1000e6
%    
%     figure()
%     subplot(2,1,1)
%     plot(Xplot, location_ver);
%     subplot(2,1,2)
%     plot(Xplot, location_hor);

    
    
    