0
votes

I have two equally-sized data-arrays (mainly zeros, and sparsely filled with ones), and make the conv of it. As a result I get this.

Now one can see a peak around -10^{-5}. My question is, how can I do the convolution such that I only get a small region around that peak?

I know that the convolution is defined from minus infinity to infinity. Mathematically I would want to change those limits to (in my example) [-1.5*10^5,-0.5*10^-5].

Thanks alot for your help!


edit

I found the solution: One can use xcorr(a,fliplr(b)) instead of conv(a,b). Now xcorr has the option "maxlags", which is exactly the thing I was searching for.

1
It is only defined from minus infinity to infinity if you have functions mapping some value to every real number. If you have intervals, or arrays in your case, then convolution is only applied to (at most) to where the arrays have some overlap. - heltonbiker
heltonbiker: OK, sure, I should have been more preceis. My question goes exactly in that direction: is it possible in MATLAB to restrict the interval further? In my case, to extract the info of the peak without wasting time calculating the other things? - Mario Krenn
You can use a slice from the original array as the convolution input, instead of the whole array. - heltonbiker

1 Answers

0
votes

You can reduce the number of output values of conv, but not arbitrarily. Try 'same' or 'valid' options:

C = CONV(A, B, SHAPE) returns a subsection of the convolution with size specified by SHAPE:

  'full'  - (default) returns the full convolution,
  'same'  - returns the central part of the convolution
            that is the same size as A.
  'valid' - returns only those parts of the convolution 
            that are computed without the zero-padded edges. 
            LENGTH(C)is MAX(LENGTH(A)-MAX(0,LENGTH(B)-1),0).

To specify arbitrary output limits, you probably need to do the convolution manually with a user-defined function. But it may be more efficient to use conv and then trim the output.