6

I need to convolve this curve with a parametrized Gaussian function centered at 3934.8A:

enter image description here

The problem I see is that my curve is a discrete array and the Gaussian is a continuous function. How can I make this work?

2
  • 1
    blancosilva.wordpress.com/teaching/mathematical-imaging/… Commented Jun 10, 2014 at 19:30
  • 1
    Can you discretize your Gaussian (with np.histogram or a list comprehension or something) and pass it to np.convolve? That seemed to work fine for me. Commented Jun 10, 2014 at 19:59

1 Answer 1

11

To do this, you need to create a Gaussian that's discretized at the same spatial scale as your curve, then just convolve.

Specifically, say your original curve has N points that are uniformly spaced along the x-axis (where N will generally be somewhere between 50 and 10,000 or so). Then the point spacing along the x-axis will be (physical range)/(digital range) = (3940-3930)/N, and the code would look like this:

dx = float(3940-3930)/N
gx = np.arange(-3*sigma, 3*sigma, dx)
gaussian = np.exp(-(x/sigma)**2/2)
result = np.convolve(original_curve, gaussian, mode="full")

Here this is a zero-centered gaussian and does not include the offset you refer to (which to me would just add confusion, since the convolution by its nature is a translating operation, so starting with something already translated is confusing).

I highly recommend keeping everything in real, physical units, as I did above. Then it's clear, for example, what the width of the gaussian is, etc.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, is there no need for a normalization factor in the gaussian kernel?
@zwep: If your convolution needs a particular normalization (eg, if you're smoothing and want a of normalization of to 1), you would have to include that. (Btw, you don't need that normalization to be in the kernel so whether or not you include it in the kernel is your choice. Overall, my gaussian function is an example, and here I'm only describing the mechanics of the calculation, not issues around kernel choice, etc, and it would be a mistake to a priori assume this example accomplishes any particular data analysis task.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.