Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the full width half maximum of a peak

I have been trying to figure out the full width half maximum (FWHM) of the the blue peak (see image). The green peak and the magenta peak combined make up the blue peak. I have been using the following equation to find the FWHM of the green and magenta peaks: fwhm = 2*np.sqrt(2*(math.log(2)))*sd where sd = standard deviation. I created the green and magenta peaks and I know the standard deviation which is why I can use that equation.

I created the green and magenta peaks using the following code:

def make_norm_dist(self, x, mean, sd):     import numpy as np      norm = []     for i in range(x.size):         norm += [1.0/(sd*np.sqrt(2*np.pi))*np.exp(-(x[i] - mean)**2/(2*sd**2))]     return np.array(norm)  

If I did not know the blue peak was made up of two peaks and I only had the blue peak in my data, how would I find the FWHM?

I have been using this code to find the peak top:

peak_top = 0.0e-1000 for i in x_axis:     if i > peak_top:         peak_top = i 

I could divide the peak_top by 2 to find the half height and then try and find y-values corresponding to the half height, but then I would run into trouble if there are no x-values exactly matching the half height.

I am pretty sure there is a more elegant solution to the one I am trying.

like image 383
Harpal Avatar asked May 14 '12 11:05

Harpal


People also ask

What is the FWHM of a peak?

The full width half maximum (FWHM) is defined as the width of the distribution at a level that is just half the maximum ordinate of the peak. The full width tenth maximum (FWTM) is defined as the width of the distribution at a level that is 1/10 the maximum ordinate of the peak.

How do you find the FWHM of a peak in origin?

For the GAUSS function the FWHM=w*sqrt(ln4), for the VOIGT function there is approximation FWHM=0.5346wL+sqrt(0.2166*wL^2+wG^2), where wL and wG (widths of the Lorentzian and Gaussian contributions) are given by the Origin after the fitting.

How do you calculate FWHM of a peak in Python?

The green peak and the magenta peak combined make up the blue peak. I have been using the following equation to find the FWHM of the green and magenta peaks: fwhm = 2*np. sqrt(2*(math. log(2)))*sd where sd = standard deviation.


1 Answers

You can use spline to fit the [blue curve - peak/2], and then find it's roots:

import numpy as np from scipy.interpolate import UnivariateSpline  def make_norm_dist(x, mean, sd):     return 1.0/(sd*np.sqrt(2*np.pi))*np.exp(-(x - mean)**2/(2*sd**2))  x = np.linspace(10, 110, 1000) green = make_norm_dist(x, 50, 10) pink = make_norm_dist(x, 60, 10)  blue = green + pink     # create a spline of x and blue-np.max(blue)/2  spline = UnivariateSpline(x, blue-np.max(blue)/2, s=0) r1, r2 = spline.roots() # find the roots  import pylab as pl pl.plot(x, blue) pl.axvspan(r1, r2, facecolor='g', alpha=0.5) pl.show() 

Here is the result:

enter image description here

like image 89
HYRY Avatar answered Sep 22 '22 11:09

HYRY