Convolution without using conv; show table as if doing it on paper

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

What exactly are you asking for? What does the image show in relation to your problem?
I want to make a program that will show a calculation as it does in the image.
Do you just want to display the intermediate steps or do you want to store them in some sort of variable?
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.

Sign in to comment.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 26 Apr 2021

Commented:

on 27 Apr 2021

Community Treasure Hunt

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

Start Hunting!