%% Plot Channel Impulse Magnitude and Timing Offset for TDL-C Channel Model
% Define a channel configuration structure using an nrTDLChannel System object. Use delay profile TDL-C from TR 38.901 Section 7.7.2.

tdl = nrTDLChannel;
tdl.DelayProfile = 'TDL-C';
tdl.DelaySpread = 100e-9;

% Create a random waveform with a duration of 1 subframe.

tdlInfo = info(tdl);
Nt = tdlInfo.NumTransmitAntennas;
in = complex(zeros(100,Nt),zeros(100,Nt));

%  Transmit the input waveform through the channel.

[~,pathGains] = tdl(in);

% Obtain the path filters used in channel filtering.

pathFilters = getPathFilters(tdl);

% Estimate timing offset.

[offset,mag] = nrPerfectTimingEstimate(pathGains,pathFilters);

% Plot the magnitude of the channel impulse response and the timing offset estimate.

[Nh,Nr] = size(mag);
plot(0:(Nh-1),mag,'o:');
hold on;
plot([offset offset],[0 max(mag(:))*1.25],'k:','LineWidth',2);
axis([0 Nh-1 0 max(mag(:))*1.25]);
legends = "|h|, antenna " + num2cell(1:Nr);
legend([legends "Timing offset estimate"]);
ylabel('|h|');
xlabel('Channel Impulse Response Samples');

% Copyright 2018 The MathWorks, Inc.