function outwave = Delay2(WavFN,DTsec,Gain)
% The variable named "WavFN" contains the name of the .wav file to be read
% Read the data back into MATLAB - "y" is an array of the wav data
%Input signal is to be imported for analysis and can only be used within the function.  
%In this case, the user is to input specific values as there will be no default values.
%WavFN		=	Signal to be processes
%DTsec		=	Delay time of the second signal in seconds
%Gain		=	Amount of gain added to the second signal			
%Input variables: 
%•	Delay time = 0 - 1
%•	Gain = 1 – 3
%Gain values lower than 1 will have no effect on delay filter.

[y, Fs] = wavread(WavFN);
n = length(y);
% Calculate the desired delay time in terms of samples
DTsamp = round(DTsec * Fs);
% Create an arrays to hold the delayed waveform and combined waveform
y2 = y; 
y3 = y; 
for j=1:DTsamp,
   y2(j)=0;
end
% fill y2 with the delayed samples
for j=DTsamp+1:n+DTsamp,
   y2(j)=y(j-DTsamp) * Gain;
end
% combine the delayed waveform with the original waveform
for j=1:n,
   y3(j) = y(j) + y2(j);
end
% Play the combined waveform
sound(y3, Fs);
% Plot Graph
figure('Name','Original');
plot(y);
figure('Name','Delayed');
plot(y2);
figure('Name','Combined');
plot(y3);
outwave = y3;