# Echo generation of FIR system using Matlab

How can I generate some echo to the system below? Here is my code. I would appreciate any help.

% Template for the echo cancelling problem
fs = 8000; % sampling frequency (Hz)
f = 400; % sinusoid frequency (Hz)
Tdur = 0.2; % pulse duration (s)
x = pulse(f, Tdur, fs); % Generates a pulse
x = [x zeros(1, 2*length(x))]; % zero pad for processing
n = 0:length(x)-1; % discrete time vector
t = n/fs; % continuous time vector
plot(t, x); % Plot signal
xlabel('Time (s)')
ylabel('Amplitude')
title(sprintf('Original pulse: %.2f Hz', f))
sound(x, fs); % Play the sound
Nzp = floor(fs*Tzp);
nzp = 1:Nzp;
xzp = [x zeros(1,Nzp-length(x))];
figure(2)
plot(nzp/fs,xzp); xlabel('Time (s)'); ylabel('Amplitude');
title(['Original pulse, zero-padded to ' num2str(Tzp,3) ' s'])
pause; sound(xzp);
% Generate echoes
Tdel = 0.1; % echo delay (s)
alpha = 0.5; % echo gain
Ndel = floor(Tdel*fs); % echo delay (samples)
b= [1 zeros(1,Ndel-1) alpha]; a = 1; % filter coefficients
y = filter(b,a,xzp);
figure(3)
plot(nzp/fs,y); xlabel('Time (s)'); ylabel('Amplitude');
title(['Echoed signal, gain = ' num2str(alpha,3)]);
pause; sound(y);
function x = pulse(f, Tdur, fs)
% Sinusoid multiplied by a Hann window function.
% f sinsusoid frequency (Hz)
% Tdur duration (s)
% fs sampling frequency (Hz)
nmax = floor(Tdur*fs); % duration (samples)
n = [1:nmax]; % discrete time index
x = hann(nmax).'.* cos(2*pi*f*n/fs); % waveform samples
end


In order to simulate a linear echo $$E$$ one will implement the following convolution:
$$E = S * H,$$
where $$S$$ is your sampled signal and $$H$$ is an echo path impulse response, both with the same sampling frequency.
The particular form of the impulse response $$H$$ depends on the echo path. For example, $$H$$ may include $$N$$ zero values at the beginning to simulate an echo delay $$N$$.
Note, that in case of an acoustic echo, the linear impulse response $$H$$ may be not enough since an echo path is usually non-linear.