查找峰的全宽的一半最大值 [英] Finding the full width half maximum of a peak

查看:140
本文介绍了查找峰的全宽的一半最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试找出蓝色峰的半峰全宽(FWHM)(参见图片).绿色峰和品红色峰的总和构成了蓝色峰.我一直在使用以下方程式来查找绿色和品红色峰的FWHM:fwhm = 2*np.sqrt(2*(math.log(2)))*sd其中sd =标准偏差.我创建了绿色和品红色峰,我知道标准偏差,这就是为什么我可以使用该方程的原因.

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) 

如果我不知道蓝色峰是由两个峰组成的,而我的数据中只有蓝色峰,那么我将如何找到FWHM?​​

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

我可以将peak_top除以2以找到半高,然后尝试查找与半高相对应的y值,但是如果没有x值与半高完全匹配,我就会遇到麻烦.

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.

推荐答案

您可以使用样条曲线拟合[蓝色曲线-peak/2],然后找到其根:

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()

这是结果:

这篇关于查找峰的全宽的一半最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆