How to properly normalize convolution of Gaussian and Lorentzian

In summary, the conversation discusses plotting the normalized convolution of a Gaussian with a Lorentzian, using the definitions in terms of full width half maximum (fwhm) provided in an attached image. The code attempts to calculate this convolution, but the print statements with np.trapz() do not return 1 in both cases, indicating a possible missing normalization factor when the parameter fwhm is changed. The conversation also mentions the possibility of changing the fwhm and plotting different convolutions.
  • #1
schniefen
178
4
TL;DR Summary
The title sums it up and this is something I'd like to plot. I'd also like for the Gaussian to be centered at ##x=0## whereas the Lorentzian should be centered at ##x=1##.
I'd like to plot the normalized convolution of a Gaussian with a Lorentzian (see the definitions in terms of full width half maximum (fwhm) in the attached image). Here is my attempt, but the print statements with np.trapz() do not return 1 in both cases, but rather ##\approx##0.2. I'd also like to change the fwhm and plot different convolutions. Is there a normalization factor missing when the parameter fwhm is changed?

Python:
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))

Screen Shot 2021-03-04 at 12.28.54.png

plotconv.png
 
Last edited:
Technology news on Phys.org
  • #2
Since np.trapz() returns the normalization factor, maybe divide the dist_main and dist_broad within np.convolve() by the respective factors?
 

FAQ: How to properly normalize convolution of Gaussian and Lorentzian

What is the purpose of normalizing a convolution of Gaussian and Lorentzian?

The purpose of normalizing a convolution of Gaussian and Lorentzian is to ensure that the resulting function has a maximum value of 1. This allows for easier comparison and interpretation of the data, as well as making it easier to perform further calculations and analysis.

How is the normalization factor calculated for a convolution of Gaussian and Lorentzian?

The normalization factor for a convolution of Gaussian and Lorentzian can be calculated by integrating the product of the two functions over the entire range of values. This integral can then be solved using numerical methods or by using a computer program. The resulting value can then be used as the normalization factor.

Can the normalization factor be negative for a convolution of Gaussian and Lorentzian?

No, the normalization factor for a convolution of Gaussian and Lorentzian cannot be negative. The normalization factor is calculated by integrating the product of two positive functions, therefore the resulting value must also be positive. This ensures that the normalized function will have a maximum value of 1.

What are the benefits of normalizing a convolution of Gaussian and Lorentzian?

Normalizing a convolution of Gaussian and Lorentzian allows for easier comparison and interpretation of data, as well as making it easier to perform further calculations and analysis. It also ensures that the resulting function has a maximum value of 1, making it easier to identify and analyze the peaks in the data.

Is the normalization of a convolution of Gaussian and Lorentzian always necessary?

No, the normalization of a convolution of Gaussian and Lorentzian is not always necessary. It depends on the specific application and the desired outcome. In some cases, the unnormalized function may be more useful or provide more meaningful information. However, in most cases, normalization is recommended to ensure consistency and easier interpretation of the data.

Similar threads

Replies
9
Views
4K
Replies
15
Views
2K
Replies
16
Views
1K
Replies
4
Views
5K
Replies
6
Views
1K
Replies
1
Views
3K
Replies
4
Views
4K
Replies
1
Views
1K
Replies
5
Views
3K
Back
Top