% plot_BuildingsEye - plot eye diagram for a signal distorted by ISI

%% initialization
load PropData

fc = 1e9;                 % carrier frequency
tau = PropData.Delay/1e9; % delays were measures in nanoseconds.
% compute attenuation with phase correctionf for delay
Fields = PropData.Field .* exp( -j*2*pi*fc*tau)/norm(PropData.Field); 

fsT = 20;                   % samples per symbol

Pulse    = RaisedCos(fsT);
Alphabet = [ 1 -1 ];
Priors   = 0.5*[1 1];
Ns       = 1000;

%% transmitted signal
Symbols = RandomSymbols(Ns, Alphabet, Priors);
Signal  = LinearModulation(Symbols, Pulse, fsT);

%% compute discrete-time impulse response at given resolution 1/fs
Ts            = T/fsT;              % sampling period
min_tau       = min(tau);           % smallest delay
% quantize delays to sampling resolution
tau_quantized = floor( (tau-min_tau)/Ts );    

hh = zeros(1, max(tau_quantized) );
for kk = 0:max(tau_quantized)
    FieldInd = ( tau_quantized == kk );
    
    % sum all paths with delays between kk*Ts and (kk+1)*Ts
    hh(kk+1) = sum( Fields(FieldInd) );
end

%% received signal 
% convolution of tx signal and channel impulse response
Received = conv( Signal, hh );

%% plot
tt = ( 0 : length(Received)-1 )*Ts;

subplot(2,1,1)
plot( tt(1:2*fsT)/1e-6, real(reshape(Received(1:Ns*fsT), 2*fsT, [ ] )) );
grid
xlabel( 'Time (\mus)' )
ylabel( 'Amplitude' )

subplot(2,1,2)
plot( tt(1:2*fsT)/1e-6, imag(reshape(Received(1:Ns*fsT), 2*fsT, [ ] )) );
grid
xlabel( 'Time (\mus)' )
ylabel( 'Amplitude' )

