Skip to main content
added 52 characters in body
Source Link
endolith
  • 16k
  • 8
  • 70
  • 121

You're doing circular convolution, which wraps both signals around in a circle before sliding them past each other. You're convolving [..., 1, 2, 3, 4, 1, 2, 3, 4, ...] with [..., 5, 4, 3, 2, 5, 4, 3, 2, ...] in other words.

What you probably want is linear convolution, which you can get by padding f and g with zeros:

f = np.concatenate((f, np.zeros(4)))
g = np.concatenate((g, np.zeros(4)))

so that when the end wraps around and overlaps the beginning, it's multiplied by zero and has no effect on the output. Then throw away the extra zeros at the end. (This is what scipy.signal.convolve does anyway)

You're doing circular convolution, which wraps both signals around in a circle before sliding them past each other. You're convolving [..., 1, 2, 3, 4, 1, 2, 3, 4, ...] with [..., 5, 4, 3, 2, 5, 4, 3, 2, ...] in other words.

What you probably want is linear convolution, which you can get by padding f and g with zeros:

f = np.concatenate((f, np.zeros(4)))
g = np.concatenate((g, np.zeros(4)))

so that when the end wraps around and overlaps the beginning, it's multiplied by zero and has no effect on the output. Then throw away the extra zeros at the end.

You're doing circular convolution, which wraps both signals around in a circle before sliding them past each other. You're convolving [..., 1, 2, 3, 4, 1, 2, 3, 4, ...] with [..., 5, 4, 3, 2, 5, 4, 3, 2, ...] in other words.

What you probably want is linear convolution, which you can get by padding f and g with zeros:

f = np.concatenate((f, np.zeros(4)))
g = np.concatenate((g, np.zeros(4)))

so that when the end wraps around and overlaps the beginning, it's multiplied by zero and has no effect on the output. Then throw away the extra zeros at the end. (This is what scipy.signal.convolve does anyway)

Source Link
endolith
  • 16k
  • 8
  • 70
  • 121

You're doing circular convolution, which wraps both signals around in a circle before sliding them past each other. You're convolving [..., 1, 2, 3, 4, 1, 2, 3, 4, ...] with [..., 5, 4, 3, 2, 5, 4, 3, 2, ...] in other words.

What you probably want is linear convolution, which you can get by padding f and g with zeros:

f = np.concatenate((f, np.zeros(4)))
g = np.concatenate((g, np.zeros(4)))

so that when the end wraps around and overlaps the beginning, it's multiplied by zero and has no effect on the output. Then throw away the extra zeros at the end.