# 2.1.17.2.1.3 peak_pos

## Description

This function evaluates the parameters' value of the Gaussian function:

$y = y_0 + \frac{A}{w\sqrt{\frac{\pi}{2}}}e^{-2\frac{(x-x_c)^2}{w^2}}$

Where FWHM means Full Width at Half Maximum

$FWHM = w\sqrt{\ln{4}}$

## Syntax

double peak_pos( Curve & data, double * pWidth = NULL, double * pBaseline = NULL, double * pArea = NULL, double * pHeight = NULL, double * pCentroid = NULL, bool bHaveBase = TRUE, bool bSortDataFirst = TRUE, int * pErr = NULL, int * pnDir = NULL )

## Parameters

data
[input] Source data.
pWidth
[output] Peak width, which equals to 2 * sigma (standard error of the Gaussian distribution).
pBaseline
[output] Peak baseline
pArea
[output] Peak area.
pHeight
[output] Peak height
pCentroid
[output] The x position of the centroid
bHaveBase
[input] Reserved parameter, for later use.
bSortDataFirst
[input] Indicate whether need to sort the input points before calculate the result.
pErr
[output] Error code, OE_NOERROR for success, otherwise returns error.
pnDir
[output] Direction of the peak, 1 for positive while -1 for negative.

## Return

X position of the peak center.

## Examples

EX1

void peak_pos_ex()
{
//import data into new worksheet, user may import this data manully.
LT_execute("win -t W Origin;");
LT_execute("open -w %(system.path.program\$)Samples\Curve Fitting\Gaussian.dat;");

Worksheet wks = Project.ActiveLayer();
if ( wks )
{
Curve crv(wks, 0, 1);

double dxc, dWidth, dBaseline, dArea, dHeight, dCentroid;
int nErr, nPeakDirection;
dxc = peak_pos(crv, &dWidth, &dBaseline, &dArea, &dHeight, &dCentroid, TRUE, TRUE, &nErr, &nPeakDirection);

printf("Peak's width is %.4lf, height is %.4lf, baseline is %.4lf, center is %.4lf\n", dWidth, dHeight, dBaseline, dxc);
}
}

## Remark

This function can be used for fitting function parameter initialization.

origin.h