# Add echo as described by difference equation to audio signal (in MATLAB) [closed]

A simple linear system is echo. It can be described by equation $$y[n] = x[n]+ k\,x[n−d],$$ where $$n$$ represents sample index, $$k$$ represents an attenuation coefficient, and $$d$$ represents time lag.

How can I add echo to an input signal in MATLAB with convolution?

I'm new at MATLAB.

• Hint: what is the impulse response of a system that outputs $y[n]$ when the input is $x[n]$? – MBaz Nov 8 '18 at 23:43
• I fixed the question. Input is just an audio signal not x[n]. So the question is how can i add echo with lag and attenuation factor based on that equation to some audio signal? I would really appreciate if someone can demonstrate me this in matlab. – ulica una Nov 8 '18 at 23:56
• Other hint: Think about expressing this formula via matrix operations. What sort of matrix operation could give you $y[n]$? – A_A Nov 9 '18 at 9:06

The impulse response $$h[n]$$ can be obtained by inspection: $$h[n] = \delta[n] + k \delta[n - d]$$

In MATLAB notation this would be:

h = [1, zeros(1,d-1), k];


The output is computed by:

y = conv(x, h);


Note that the time sample indices for the vector y will be as follows, assuming that both x and h are indexed where the first element corresponds to time $$n=0$$:

ny = 0:(length(x) + length(h) - 2);