convolution product calculater impulse response

3 views (last 30 days)
can anyone tell me where is the problem
LDKI
x(n)=[1,3,-2,5,7]
h(n)= [1,5,8,-5,13]
x=[1,3,-2,5,7]
h= [1,5,8,-5,13]
dx=length(x)
dh=length(h)
dy=dx+dh-1
for i=1:dy
y1(i)=0;
for j=1:dx
y1(i)=y1(i)+x(j)*h(i-j+1)
end
end
check1=conv(x1,h1)

Accepted Answer

David Goodmanson
David Goodmanson on 19 Feb 2022
Edited: David Goodmanson on 19 Feb 2022
Hi amjad,
You have to keep the indices within the bounds set by dx and dh. For the j loop, you can use the line
for j=max(1,i-dh+1):min(i,dx)
Also, in case you run the script more than once with different x and h, it pays to initialize y1 with
y1 = zeros(1,dy);

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!