# Peak shapes

Some various peak shapes that I've found useful in doing things like crystallite size distributions, solid solutions and the like.

Peak shape is defined by a FWHM, not a standard deviation. The lognormal peak is defined by a peak position (being the point of maximum intensity) and a FWHM, which is naturally asymmetric. All peak areas are normalised to 1 and allow for scaling. They will work with >=v5.

If you want to use fit_objs, then look at the end of this page.

Gaussian

```macro & Gau(& A, & p, & w, & x)	{
A (2 Sqrt(Ln(2)/Pi)/w) Exp(-4 Ln(2) ((x-p)/w)^2)
}```

Lorenztian

```macro & Lor(& A, & p, & w, & x)	{
2 A w / (Pi (w^2 + 4 (x-p)^2))
}```

Pearson VII

```macro & PeaVII(& A, & p, & w, & m, & x)	{
A (2 Sqrt((2^(1/m)-1)/(w^2)) Gamma_Approx(m)/(Sqrt(Pi) Gamma_Approx(m-1/2))) ((w/2)^(2 m)/((w/2)^2 + (2^(1/m) - 1)*(x-p)^2)^m)
}```

Lognormal

```macro & lognormal(& int, & posn, & fwhm, & x)	{
int/(Sqrt(2 Pi) LN_sigma(posn,fwhm) x) Exp(-((Ln(x)-LN_mu(posn,fwhm))/(Sqrt(2) LN_sigma(posn,fwhm)))^2)
}

macro & LN_r(& p, & w) {
(w + Sqrt(4 p^2 + w^2)) / (2 p)
}
macro & LN_mu(& p, & w) {
LN_r(p,w)^2/(2 Ln(2)) + Ln(p)
}
macro & LN_sigma(& p, & w) {
LN_r(p,w)/Sqrt(2 Ln(2))
}```

pseudo-Voigt

```macro & pV(& A, & p, & w, & n, & x)	{
n Lor(A,p,w,x) + (1-n) Gau(A,p,w,x)
}```

Split functions

```'all are normalised to unit area'
macro & split_Gaussian(& int,& posn,& hwL,& hwR,& x)	{
If(x < posn, (Gau(int,posn, 2*hwL,x)/Gau(1,posn, 2*hwL,0))/((hwL + hwR) Sqrt(Pi / Ln(2))/2) ,
(Gau(int,posn, 2*hwR,x)/Gau(1,posn, 2*hwR,0))/((hwL + hwR) Sqrt(Pi / Ln(2))/2)
)
}

macro & split_Lorentzian(& int,& posn,& hwL,& hwR,& x)	{
If(x < posn, (Lor(int,posn, 2*hwL,x)/Lor(1,posn, 2*hwL,0))/(Pi (hwL + hwR) / 2) ,
(Lor(int,posn, 2*hwR,x)/Lor(1,posn, 2*hwR,0))/(Pi (hwL + hwR) / 2)
)
}

macro & split_PV(& int,& posn,& hwL,& hwR, & nL, & nR, & x)	{
If(x < posn, (pV(int,posn, 2*hwL, nL, x)/pV(1,posn, 2*hwL, nL, 0))/((Pi (Sqrt(Pi Ln(2)) (hwL+hwR) - (Sqrt(Pi Ln(2)) - 1) ( hwR nL + hwL nR))) / (2 ( nL (Sqrt(Pi Ln(2)) - 1) - Sqrt(Pi Ln(2))) ( nR (Sqrt(Pi Ln(2)) - 1) - Sqrt(Pi Ln(2))))) ,
(pV(int,posn, 2*hwR, nR, x)/pV(1,posn, 2*hwR, nR, 0))/((Pi (Sqrt(Pi Ln(2)) (hwL+hwR) - (Sqrt(Pi Ln(2)) - 1) ( hwR nL + hwL nR))) / (2 ( nL (Sqrt(Pi Ln(2)) - 1) - Sqrt(Pi Ln(2))) ( nR (Sqrt(Pi Ln(2)) - 1) - Sqrt(Pi Ln(2)))))
)
}

macro & split_PeaVII(& int,& posn,& hwL,& hwR, & mL, & mR, & x)	{
If(x < posn, (PeaVII(int,posn, 2*hwL, mL, x)/PeaVII(1,posn, 2*hwL, mL, 0))/(Sqrt(Pi) (((hwR Gamma_Approx(mL) Gamma_Approx(mR - (1/2))) / Sqrt(2^(1/mR)-1)) + ((hwL Gamma_Approx(mR) Gamma_Approx(mL - (1/2))) / Sqrt(2^(1/mL)-1))) / (2 Gamma_Approx(mL) Gamma_Approx(mR))) ,
(PeaVII(int,posn, 2*hwR, mR, x)/PeaVII(1,posn, 2*hwR, mR, 0))/(Sqrt(Pi) (((hwR Gamma_Approx(mL) Gamma_Approx(mR - (1/2))) / Sqrt(2^(1/mR)-1)) + ((hwL Gamma_Approx(mR) Gamma_Approx(mL - (1/2))) / Sqrt(2^(1/mL)-1))) / (2 Gamma_Approx(mL) Gamma_Approx(mR)))
)
}

macro & split_Lognormal(& int,& posn,& hwL,& hwR,& x)	{
If(x < posn, 2 lognormal(int,posn,2 hwL,x) / (1 + (lognormal(int,posn,2 hwL,posn)/lognormal(int,posn,2 hwR,posn))),
2 lognormal(int,posn,2 hwR,x) (lognormal(int,posn,2 hwL,posn)/lognormal(int,posn,2 hwR,posn)) / (1 + (lognormal(int,posn,2 hwL,posn)/lognormal(int,posn,2 hwR,posn)))
)
}```

Macros set up to insert fit objects:

```macro Gau_fo(int, int_v, posn, posn_v, fwhm, fwhm_v) {
#m_argu int
#m_argu posn
#m_argu fwhm
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(fwhm, fwhm_v, min 0.0001 max 10)

fit_obj = Gau(CeV(int, int_v), CeV(posn, posn_v), CeV(fwhm, fwhm_v), X);
}
macro sGau_fo(int, int_v, posn, posn_v, hwL, hwL_v, hwR, hwR_v) {
#m_argu int
#m_argu posn
#m_argu hwL
#m_argu hwR
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(hwL, hwL_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(hwR, hwR_v, min 0.0001 max 3)

fit_obj = sGau(CeV(int, int_v), CeV(posn, posn_v), CeV(hwL, hwL_v), CeV(hwR, hwR_v), X);
}

macro Lor_fo(int, int_v, posn, posn_v, fwhm, fwhm_v) {
#m_argu int
#m_argu posn
#m_argu fwhm
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(fwhm, fwhm_v, min 0.0001 max 10)

fit_obj = Lor(CeV(int, int_v), CeV(posn, posn_v), CeV(fwhm, fwhm_v), X);
}
macro sLor_fo(int, int_v, posn, posn_v, hwL, hwL_v, hwR, hwR_v) {
#m_argu int
#m_argu posn
#m_argu hwL
#m_argu hwR
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(hwL, hwL_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(hwR, hwR_v, min 0.0001 max 3)

fit_obj = sLor(CeV(int, int_v), CeV(posn, posn_v), CeV(hwL, hwL_v), CeV(hwR, hwR_v), X);
}

macro pV_fo(int, int_v, posn, posn_v, fwhm, fwhm_v, mix, mix_v) {
#m_argu int
#m_argu posn
#m_argu fwhm
#m_argu mix
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(fwhm, fwhm_v, min 0.0001 max 10)
If_Local_Eqn_Rpt(mix, mix_v, min 0 max 1)

fit_obj = pV(CeV(int, int_v), CeV(posn, posn_v), CeV(fwhm, fwhm_v), CeV(mix, mix_v), X);
}
macro spV_fo(int, int_v, posn, posn_v, hwL, hwL_v, hwR, hwR_v, nL, nL_v, nR, nR_v) {
#m_argu int
#m_argu posn
#m_argu hwL
#m_argu hwR
#m_argu nL
#m_argu nR
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(hwL, hwL_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(hwR, hwR_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(nL, nL_v, min 0 max 1)
If_Local_Eqn_Rpt(nR, nR_v, min 0 max 1)

fit_obj = spV(CeV(int, int_v), CeV(posn, posn_v), CeV(hwL, hwL_v), CeV(hwR, hwR_v), CeV(nL, nL_v), CeV(nR, nR_v), X);
}

macro Pea7_fo(int, int_v, posn, posn_v, fwhm, fwhm_v, m, m_v) {
#m_argu int
#m_argu posn
#m_argu fwhm
#m_argu m
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(fwhm, fwhm_v, min 0.0001 max 10)
If_Local_Eqn_Rpt(m, m_v, min 0.50001 max 20)

fit_obj = Pea7(CeV(int, int_v), CeV(posn, posn_v), CeV(fwhm, fwhm_v), CeV(m, m_v), X);
}
macro sPea7_fo(int, int_v, posn, posn_v, hwL, hwL_v, hwR, hwR_v, mL,mL_v, mR, mR_v) {
#m_argu int
#m_argu posn
#m_argu hwL
#m_argu hwR
#m_argu mL
#m_argu mR
If_Local_Eqn_Rpt(int, int_v, min 0)
If_Local_Eqn_Rpt(posn, posn_v,)
If_Local_Eqn_Rpt(hwL, hwL_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(hwR, hwR_v, min 0.0001 max 3)
If_Local_Eqn_Rpt(mL, mL_v, min 0.50001 max 20)
If_Local_Eqn_Rpt(mR, mR_v, min 0.50001 max 20)

fit_obj = sPea7(CeV(int, int_v), CeV(posn, posn_v), CeV(hwL, hwL_v), CeV(hwR, hwR_v), CeV(mL, mL_v), CeV(mR, mR_v), X);
}```