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
[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;