%% Plot Estimated Channel Magnitude Response for CDL-D Channel Model
% Define a channel configuration structure using an nrCDLChannel System object. Use delay profile CDL-C from TR 38.901 Section 7.7.1.

 cdl = nrCDLChannel;
 cdl.DelayProfile = 'CDL-D';
 cdl.DelaySpread = 30e-9;
 cdl.MaximumDopplerShift = 5;

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

SR = 15.36e6;
T = SR*1e-3;
cdl.SampleRate = SR;
cdlInfo = info(cdl);
Nt = cdlInfo.NumTransmitAntennas;
in = complex(randn(T,Nt),randn(T,Nt));

%  Transmit the input waveform through the channel. Obtain the path filters used in channel filtering.

[~,pathGains,sampleTimes] = cdl(in);
pathFilters = getPathFilters(cdl);

% Perform timing offset estimation using the path filter and path gains.

offset = nrPerfectTimingEstimate(pathGains,pathFilters);

% Perform perfect channel estimation. Use the specified number of blocks, subcarrier spacing, slot number, timing offset, and sample times.

NRB = 25;
SCS = 15;
nSlot = 0;
hest = nrPerfectChannelEstimate(pathGains,pathFilters,...
    NRB,SCS,nSlot,offset,sampleTimes);
size(hest)

% Plot the estimated channel magnitude response for the first receive antenna.

figure;
surf(abs(hest(:,:,1)));
shading('flat');
xlabel('OFDM Symbols');
ylabel('Subcarriers');
zlabel('|H|');
title('Channel Magnitude Response');

% Copyright 2018 The MathWorks, Inc.