convolution product calculater impulse response

1 次查看(过去 30 天)
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)

采纳的回答

David Goodmanson
David Goodmanson 2022-2-19
编辑:David Goodmanson 2022-2-19
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by