Filter löschen
Filter löschen

convolution product calculater impulse response

1 Ansicht (letzte 30 Tage)
amjad hammad
amjad hammad am 17 Feb. 2022
Kommentiert: amjad hammad am 19 Feb. 2022
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)

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 19 Feb. 2022
Bearbeitet: David Goodmanson am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by