Convolution using 'valid' in Matlab's conv() function

血红的双手。 提交于 2019-12-11 05:35:19

问题


Here is an example of convolution given:

I have two questions here:

  1. Why is the vector 𝑥 padded with two 0s on each side? As, the length of kernel is 3. If 𝑥 is padded with one 0 on each side, the middle element of convolution output would be within the range of the length of 𝑥, why not one 0 on each side?

  2. Explain the following output to me:

     >> x = [1, 2, 1, 3];  
     >> h = [2, 0, 1];  
     >> y = conv(x, h, 'valid')      
      y =    
          3     8  
     >>   
    

    What is valid doing here in the context of the previously shown mathematics on vectors 𝑥 and ?


回答1:


  1. I can't speak as to the amount of zero padding that is proper .... That being said, any zero padding is making up data that is not there. This isn't necessarily wrong, but you should be aware that the values computing this information may be biased. Sometimes you care about this, sometimes you don't. Introducing 1 zero (in this case) would leave the middle kernel value always in the data, but why should that be a stopping criteria? Importantly, adding on 2 zeros still leaves one multiplication of values that are actually present in the data and the kernel (the x[0]*h[0] and x[3]*h[2] - using 0 based indexing). Adding on a 3rd zero (or more) would just yield zeros in the output since 3 is the length of the kernel. In other words zero padding will always yield an output that is partially based on the actual data (but not completely) for any zero padding from n=1 to n = length(h)-1 (in this case either 1 or 2).

  2. Even though zero padding with length 2 or 1 still has multiplications based on real data, some values are summed over "fake" data (those multiplied with a padded zero). In this case Matlab gives you 3 options for how you want the data returned. First, you can get the full convolution, which includes values that are biased because they include adding in 0 values that aren't really in the data. Alternatively you can get same, which means the length of the output is the length of the data y = [4 3 8 1]. This corresponds to 1 zero but note that for longer kernels you could technically get other lengths between full and same, Matlab just doesn't return those for you.

Finally, and probably most important to understand out of all this, you have the valid option. In your example only 2 samples of the output are computed from summations that occur only from multiplications over real data (i.e. from multiplying samples of the kernel with samples from x and not from zeros). More specifically:

y[2] = h[2]*x[0] + h[1]*x[1] + h[2]*x[2] = 3 //0 based indexing like example
y[3] = h[2]*x[1] + h[1]*x[2] + h[2]*x[3] = 8

Note none of the other y values are computed with only h and x, they all involve a padded zero which is not necessarily indicative of the real data. For example:

y[4] = h[2]*x[2] + h[1]*x[3] + h[2]*0 <= padded zero   


来源:https://stackoverflow.com/questions/53023281/convolution-using-valid-in-matlabs-conv-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!