Matlab 我的卷积码在完全重叠后停止工作。有什么建议吗?

Matlab 我的卷积码在完全重叠后停止工作。有什么建议吗?,matlab,signal-processing,convolution,Matlab,Signal Processing,Convolution,我试着检查它停在什么地方。在“h”和“x”完全重叠之后。但在此之前,它的工作正如预期。我不确定我在这里遗漏了什么,因为逻辑似乎是合理的 这让我相信,也许我缺少了某种语法,或者无法完全控制MATLAB %in1 = input('Enter the input sequence:'); %in2 = input('Enter the impulse sequence:'); x= [1 2 3]; h= [1 1 1]; if length(in2)>length(in1) x=

我试着检查它停在什么地方。在“h”和“x”完全重叠之后。但在此之前,它的工作正如预期。我不确定我在这里遗漏了什么,因为逻辑似乎是合理的

这让我相信,也许我缺少了某种语法,或者无法完全控制MATLAB

%in1 = input('Enter the input sequence:');
%in2 = input('Enter the impulse sequence:');

x= [1 2 3];
h= [1 1 1];

if length(in2)>length(in1)
    x= in2;
    h= in1;
end

c= zeros(1,length(h)+length(x)-1);
w= length(h);
h= flip(h); h=[h, zeros(1,(length(x)+length(h)-2))];disp(h);
x= [zeros(1,w-1), x, zeros(1,w-1)]; disp(x);disp(w);

for n=1:length(x)-(w-1)
    c(n)= sum((h(1+n-1):h(w+n-1)).*(x(1+n-1):x(w+n-1)));disp(c);
    h= circshift(h,1);disp(h);disp(x);
end



有什么线索吗?

你为什么要用pad
h
?不要那样做!尽管存在是否应该填充的问题,但您是否考虑过使用断点并查看for循环中到底发生了什么?请阅读
     c= 1     0     0     0     0


     h= 0     1     1     1     0     0     0

     x= 0     0     1     2     3     0     0

     c= 1     3     0     0     0


     h= 0     0     1     1     1     0     0

     x= 0     0     1     2     3     0     0

     c= 1     3     6     0     0


     h= 0     0     0     1     1     1     0

     x= 0     0     1     2     3     0     0

    %At this point I just get zeros

     c= 1     3     6     0     0


     h= 0     0     0     0     1     1     1

     x= 0     0     1     2     3     0     0

     c= 1     3     6     0     0