Handover
% Parameters
speed = 50; % Mobile speed in m/s
time = 100; % Total simulation time in seconds
dt = 1; % Time step in seconds
num_steps = time / dt;
P0rx = -100; % Minimum received signal strength to avoid drop (dBm)
Phrx = -85; % Handover threshold (dBm)
margin = 5; % Handover margin (dB)
d0 = 1; % Reference distance (m)
Pt = 0; % Transmit power in dBm
path_loss_exp = 3.5; % Path loss exponent
sigma_shadow = 6; % Shadowing standard deviation in dB
% Positions of BS A and B
pos_A = 0;
pos_B = 1000;
% Initialize mobile position
pos_mobile = 0;
% Initialize counters
handoffs = 0;
call_drops = 0;
connected_to = 'A';
for t = 1:num_steps
pos_mobile = pos_mobile + speed * dt;
% Distance to base stations
d_A = abs(pos_mobile - pos_A);
d_B = abs(pos_mobile - pos_B);
% Received power with path loss and shadowing
Prx_A = Pt - 10*path_loss_exp*log10(d_A/d0) + randn * sigma_shadow;
Prx_B = Pt - 10*path_loss_exp*log10(d_B/d0) + randn * sigma_shadow;
% Call drop check
if strcmp(connected_to, 'A') && Prx_A < P0rx
call_drops = call_drops + 1;
connected_to = 'B'; % Attempt reconnection
continue;
elseif strcmp(connected_to, 'B') && Prx_B < P0rx
call_drops = call_drops + 1;
connected_to = 'A';
continue;
end
% Handover condition
if strcmp(connected_to, 'A') && Prx_B > Phrx && Prx_A < (Phrx - margin)
connected_to = 'B';
handoffs = handoffs + 1;
elseif strcmp(connected_to, 'B') && Prx_A > Phrx && Prx_B < (Phrx - margin)
connected_to = 'A';
handoffs = handoffs + 1;
end
end
% Output results
fprintf('Number of Handoffs: %d\n', handoffs);
fprintf('Number of Call Drops: %d\n', call_drops);