convolution product calculater impulse response

조회 수: 3 (최근 30일)
amjad hammad
amjad hammad 2022년 2월 17일
댓글: amjad hammad 2022년 2월 19일
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