Electrical – Matlab code to determine and plot impulse response

filteringMATLAB

I have a signal y[n], represented by the vector y in this form

  • y[n] =x[n] + ax[n−N]

About this signal:

  1. x[n] is the uncorrupted speech signal which has been delayed by N samples and added back in with its amplitude decreased by a<1
  2. N= 1000, and the echo amplitude,a= 0.5.

I need help with:
Determining and plotting the impulse response of the signal. Also I was hoping to store this impulse response in the vector for 0≤n≤1000

What I have and which does not work:

% Testing the input:
sound(y,8192)

% echotime,N= 1000, and 
% the echo amplitude,a= 0.5.
N = 1000;
a = 0.5;

n = [0:1000]; %time vector


for i=0:1000
    y(i)=x(i)+a*x(i+N)
end
stem(n,y) %output plot

This would give me an error lie:

Undefined function or variable 'x'.

Error in (line 15)
    y(i)=x(i)+a*x(i+N)

Best Answer

Determining and plotting the impulse response of the signal.

You are confusing signals and systems. Systems have impulse responses, signals don't. You can calculate the output signal of a linear time invariant system for any given input vy convolving the input signal with the impulse response of the system.

% create the impulse response
M = 1; % MATLAB indexing offset
N = 1000;
h = zeros(1001,1); 
h(M+0) = 1;
h(M+1000) = 1;
stem(h);
Related Topic