%This function returns a predicted received power map for the base station
%2 fields of precalculated maps were added to the original base station  
%structures:
%.blocked = a map of all blocked locations
%.dir_loss_map = a map of the loss from the antenna direction attenuation
%(in dB)
function [map] = predict_map(Station, vr)
%constants
rows = size(Station.terrain,1);
cols = size(Station.terrain,2);
z = double(Station.terrain)+3;%the +3 accounts for car and receiving antenna height
gr = 0;%Gain of receiving antenna, assumed to be 0dB
L = 1;%system loss factor not related to propagation L>=1
n_1 = 2.78;%path loss exponent
x = double([ones(rows,1)*[1:cols]]);
y = double(transpose([1:rows])*ones(1,cols));

%base station characteristics
eirp = double(Station.cellSite.eirp);
height = Station.cellSite.height+double(Station.terrain(Station.cellSite.BSy,Station.cellSite.BSx));
BSx = double(Station.cellSite.BSx);
BSy = double(Station.cellSite.BSy);
BSangle = double(Station.cellSite.azimuth);
f = double(Station.cellSite.freq)*10^6;
wavelength = 299792458/f;
cellSize = double(Station.cellSite.cellSize);

%other characteristics
delta_x = x-BSx;
delta_y = y-BSy;
delta_z = double(Station.terrain)-height;
%REMEMBER BASE STATION PT
%path_distance
dist = cellSize * (((delta_x).^2+(delta_y).^2+(delta_z).^2).^(0.5));

%blocked path loss, n_2 is the loss associated with being blocked
n_2 = 6.31;
PL_blocked = double(Station.blocked)*(n_2);

%remember to add PwrRec at BSx,BSy condition

%link budget P_R = EIRP + G_R + 20log10(wavelength/4pi) +
%20log10(path_distance) + system loss + extra path loss

map = eirp + gr + 20*log10(wavelength/(4*pi)) - n_1*10*log10(dist) - ...
    10*log(L) + Station.dir_loss_map - PL_blocked + vr;
