% plot_BuildingsTDMA - plot time-varying response to sinusoidal input
%                      together with TDMA time-slots

clf

% load data
load PropData;       % loads PropData structure

ff = 0;              % base-band equivalent frequency

v  = 10;             % velocity in m/s
dT = 1e-3;           % time increment between snapshots
NT = 500;           % number of snap-shots
fc = 1e9;            % carrier frequency

c = 299792458;       % speed of light in m/s

tt = (0:NT-1)*dT;                    % time axis
tau   = PropData.Delay/1e9;          % delays were measured in nanoseconds.
theta = PropData.Arrival_Phi*pi/180; % arrival angles in radians
Dopplers = v/c*fc*cos(theta);

T_TDMA = 4.614e-3;  % time-slot duration
N_TDMA = 8;         % numbr of TDMA users

HH = zeros(1,NT);

for kk = 1:NT
    HH(kk) = PropData.Field.*exp(-j*2*pi*fc*tau) * exp(-j*2*pi*tau'*ff);
    tau = tau + Dopplers/fc*dT;
end

HH_max = max(abs( HH ) );
HH_min = min(abs( HH ) );

T_start = 0;
while (T_start < NT*dT)
    T_end = min( T_start + T_TDMA, NT*dT );
    fill( [T_start T_start T_end T_end], ...
        20*log10(1.1*[eps HH_max HH_max eps]), 'g')
    hold on
    
    T_start = T_start + N_TDMA*T_TDMA;
end


plot( tt, 20*log10(abs(HH)) )
xlabel( 'Time (s)')
ylabel( 'Magnitude (dB)')
axis( [0 NT*dT 20*log10([0.5*HH_min 2*HH_max]) ] )
grid


%% Store name of script for automated figure generation
ScriptName = mfilename;
