Sep-30-2020, 09:05 AM

Hello, I'm trying to replicate Matlab's convolution aka conv function.

Matlab's conv works like this:

I tried numpy convolve but documentation says it work differently, in fact:

numpy.convolve(a, v, mode) where:

- a(N,) array_like

- v(M,) array_like

- mode{‘full’, ‘valid’, ‘same’}

but the problem is that 'same' does NOT work as Matlab, in fact it says

But I don't want the output to be of length max(M,N)!!! I want it to be same size as u as Matlab's.

Any idea how to do that?

Matlab's conv works like this:

Quote:w = conv(u,v,shape) returns a subsection of the convolution, as specified by shape. For example, conv(u,v,'same') returns only the central part of the convolution, the same size as u.

I tried numpy convolve but documentation says it work differently, in fact:

numpy.convolve(a, v, mode) where:

- a(N,) array_like

- v(M,) array_like

- mode{‘full’, ‘valid’, ‘same’}

but the problem is that 'same' does NOT work as Matlab, in fact it says

Quote:Mode ‘same’ returns output of length max(M, N).

But I don't want the output to be of length max(M,N)!!! I want it to be same size as u as Matlab's.

Any idea how to do that?