% plot_BuildingsTVFreqResponse - plot time-varyibg frequency response from
%                                ray data 

% load data
load PropData;       % loads PropData structure

BW = 10e6;           % bandwidth to evaluate
N  = 200;           % number of points to plot in frequency domain
v  = 10;             % velocity in m/s
dT = 2e-3;           % time increment between snapshots
NT = 100;            % number of snap-shots
fc = 1e9;            % carrier frequency

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

ff = (0:N-1)/N*BW - BW/2; % frequency axis from -BW/2 to (nearly) BW/2
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);

HH = zeros(NT,N);

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

surfc( ff/1e6, tt/1e-3, 20*log10(abs(HH)) )
xlabel( 'Frequency (MHz)')
ylabel( 'Time (ms)' )
zlabel( '|Frequency Response| (dB)')

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