Explore BrainMass

# Matlab Program to Computer

Not what you're looking for? Search our solutions OR ask your own Custom question.

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

x(n)=(1,2,3,4,5,6,7,8,9,10)
h(n)=(1,1,-1,3,2)
Write a matlab program to computer y(n)=h(n)*h(n) (convolution) without using the matlab convolution function 'conv'. That is, write matlab code to computer the convolution sum (... using nested loops?). Then use conv(h,x) to check the work.

Plot h, x, and y using the plot function.

--

This is what I have:
x=[0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,0,0,0,0,0,0,0,0,0,0,0,0];
h=[0,0,0,0,0,0,0,0,0,0,1,1,-1,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
y=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

for n=-5:15,
for k=-100:100,
y(n+10)=y(n+10)+x(k+10)*h((n+10-(k+10)));
end;
end;

for z=-5:15,
disp (y(z+10));
end;

---

The problem is that negative indices cannot be used - so I was trying to zero pad both sets. This seems to be okay, but for k being -infinity to +infinity and all, I'm stuck. I tried moving it to -100 to +100 but I get confused. I even tried drawing cells on a paper to visually see how to convolution is to be one, but I got even more confused.

Please correct the program so that it works. Thank you!