0

I'd like to plot the normalized convolution of a Gaussian with a Cauchy-Lorentzian distribution, centered at different points. I'm using the following definitions:

Here is my attempt. When fwhm decreases to 0.005, np.trapz() does not return 1 in both cases, but approximately 0.2. Has this something to do with how the x-axis is partitioned? I'd like to change the fwhm and plot different convolutions. I'm unsure if dx is needed/what it does and if it's correctly placed.

import numpy as np
import matplotlib.pyplot as plt

#lorentzian
def loren(x,x0,fwhm):
    a=fwhm/(2*np.pi)
    y=a*1/((x-x0)**2+(fwhm/2)**2)
    return y
# gaussian
def gaussian(x, x0, fwhm):
    a = 2. / fwhm / np.sqrt(np.pi / np.log(2))
    y = a * np.exp(-4 * np.log(2) * (x-x0)**2 / fwhm**2)
    return y
# define x-axis
x = np.linspace(-5, 5, 1000)
dx = x[1] - x[0]
# the 'main distribution' centered at x0, 'broad distrbution' at x1
x0 = 1
x1 = 0
dist_main = loren(x, x0, 0.05)
dist_broad = gaussian(x, x1, 0.005)
# calculate the convolution, multiplication with dx is for normalization
dist_conv = np.convolve(dist_main, dist_broad * dx, mode='same')
# plotting
fig, ax = plt.subplots()
ax.plot(x, dist_main, label='Lorentzian')
ax.plot(x, dist_broad, label='Gaussian')
ax.plot(x, dist_conv, label='Convolution')
ax.set_title('$\Gamma_G=0.005$')
ax.legend()
plt.show()

print(np.trapz(dist_broad,x,dx))
print(np.trapz(dist_conv,x,dx))
sunny
  • 135
  • 6
  • FYI: [`scipy.special.voigt_profile`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.voigt_profile.html) – Warren Weckesser Mar 04 '21 at 20:02
  • Can one specify where the Gaussian and Cauchy distribution are centered using ```scipy.special.voigt_profile```? – sunny Mar 04 '21 at 20:04

0 Answers0