Trying to come up with a convolution function without using "conv" but i run into the error of index exceeds array bounds. This is my code so far:
x=[1,2,3,4,5,6];
h=[4,5,6];
X=[x,zeros(1,length(h)-1)];
H=[h,zeros(1,length(x)-1)];
output=length(x)+(length(h)-1);
for i=1:output
new(i)=sum(x(1:i).*fliplr(h(1:i)));
end
disp(output);
disp(new);
I get a correct value for X and H as well as the output so i am thinking my problem is in my for loop. The thought process behind that is I will multiply matrix x by flipped(k) and take the sum of that until the for loop ends.

 채택된 답변

madhan ravi
madhan ravi 2018년 10월 16일

0 개 추천

x=[1,2,3,4,5,6];
h=[4,5,6];
X=[x,zeros(1,length(h)-1)];
H=[h,zeros(1,length(x)-1)];
output=length(x)+(length(h)-1);
for i=1:output
new(i)=sum(X(1:i).*fliplr(H(1:i))); % x and h should be capital here
end
disp(output);
disp(new);

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2018년 10월 16일

답변:

2018년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by