Convolution without using conv; show table as if doing it on paper
10 views (last 30 days)
Show older comments
I need to calculate a convolution of a user entered data and do so without using the conv command. I then need to show a table of the steps in which the convoultion is calculated by hand, as if doing it paper. A homework checker essentially. The way you calculate it on hand is as shown here: 

I found 2 ways of calculating conv without using he literal conv commmand. They are as follows;
%%
x=input('Enter the coefficients for x (surround with []): ')
h=input('Enter the coefficients for h (surround with []): ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
A = [X;H];
for i=1:n+m-1
Y(i)=0;
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
%%
x=input('Enter the coefficients for x (surround with []): ');
h=input('Enter the coefficients for h (surround with []): ');
x = x';
h=h';
N = length(x)+length(h)-1;
x1 = [x; zeros(N-length(x),1)]
h1 = [h; zeros(N-length(h),1)]
filter(x1, 1, h1)
I'm really at a loss as to how to show the table. I tried creating one (A) in the first method but cant figure out how to get the calculation lines to output. It does show the X and H values
4 Comments
Steven Lord
on 27 Apr 2021
Do you just want to display the intermediate steps or do you want to store them in some sort of variable?
David Goodmanson
on 27 Apr 2021
Hi Maria,
the convolution has length(x) + length(h) - 1 = 8 elements. If you zerofill x so that it has 8 elements
x = [x zeros(1,3)];
then using
x = circshift(x,1)
at each step will progressively shift x to the right, putting harmless placeholder zeros into the unneeded array elements. After that there are some details to complete the process.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!