function signalOut = dcfApplyFading(signalIn, seed, delayVector, gainVector)
%dcfApplyFading Applies Rayleigh fading effect on the waveform
% 
%   SIGNALOUT = dcfApplyFading(SIGNALIN, SEED, DELAYVECTOR, GAINVECTOR)
%   applies multipath fast fading effect on the given waveform. 
% 
%   SIGNALOUT is the output faded out waveform, returned as a complex
%   column vector.
% 
%   SIGNALIN is a bus object of type Waveform that holds the received
%   waveform and its metadata.
%
%   SEED is the initial seed for mt19937ar random number generator
%   algorithm, specified as a double-precision, real, nonnegative integer
%   scalar.
%
%   DELAYVECTOR is a vector of delays corresponding to multiple paths,
%   specified as a double value between 0 and 1e-7 inclusive, in units of
%   seconds.
% 
%   GAINVECTOR is a vector of gains corresponding to multiple paths,
%   specified as a double value between -20 and 0 inclusive, in units of
%   dB.

%   Copyright 2019 The MathWorks, Inc.

% Configure a Rayleigh channel object
rayChan = comm.RayleighChannel('SampleRate', signalIn.channelWidth, 'MaximumDopplerShift', 0,...
    'RandomStream', 'mt19937ar with seed', 'Seed', seed,...
    'PathDelays', delayVector, 'AveragePathGains', gainVector,...
    'PathGainsOutputPort', true);
% Fadeout the given waveform
signalIn.waveform(1:signalIn.numSamples) = rayChan(signalIn.waveform(1:signalIn.numSamples));
signalOut = signalIn.waveform;
end