convolution product calculater impulse response

3 visualizaciones (últimos 30 días)
amjad hammad
amjad hammad el 17 de Feb. de 2022
Comentada: amjad hammad el 19 de Feb. de 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)

Respuesta aceptada

David Goodmanson
David Goodmanson el 19 de Feb. de 2022
Editada: David Goodmanson el 19 de Feb. de 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);

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by