Turbotanten
Turbotanten

Reputation: 396

The amplitude is changing when using Numpy Convolve

How can I make the amplitude of the convolution between the following square shape and gaussian unity?

L = 5
x = 1
t_total = L+2*x
tlist = np.linspace(0,t_total,100)

# Square pulse of length L and unit amplitude centered at x+L/2
A = (heaviside(tlist - x, 0) - heaviside(tlist - (L+x), 0))

# Gaussian with mean (x+L/2) and std 1
f = np.exp(-pow(tlist-(x+L/2),2)/2)
figure(1)
plt.plot(tlist, A)
plt.plot(tlist, f)

# Convolution
g = np.convolve(A, f, mode = 'same') * dt
figure(2)
plt.plot(tlist, g, 'g')

figure(1) enter image description here

figure(2) enter image description here

As you can see, in figure(2) the amplitude is approx 4.4. I would like to have it unity. How can I achieve that?

Upvotes: 1

Views: 1083

Answers (1)

offeltoffel
offeltoffel

Reputation: 2801

If you want the convolution of your two signals to be scaled to your gaussian function, you need to normalize. The easiest way of doing this is dividing by the sum of f:

g = np.convolve(A, f, mode = 'same') * dt / np.sum(f)

The plot yields an amplitude of 1 as requested, given that dt is also 1. Generally speaking, the amplitude will be exactly dt.

Convolution result for dt=1

Upvotes: 2

Related Questions