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 个评论
Jan
2021-4-26
What exactly are you asking for? What does the image show in relation to your problem?
Maria Pepper
2021-4-27
Steven Lord
2021-4-27
Do you just want to display the intermediate steps or do you want to store them in some sort of variable?
David Goodmanson
2021-4-27
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.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 2-D and 3-D Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!