# 5.10 Peak Analysis with Labtalk

## Summary

This tutorial demonstrates using labtalk for peak analysis.

## What You Will Learn

This tutorial will show you how to use Labtalk script to:

• Subtract a line from source data
• Find the highest peaks of each dataset
• Calculate the area, height and FWHM of the highest peak
• Create a graph of the quantities of the peak
• Create a theme of Peak Analyzer and run batch processing with the pre-saved theme

## Steps

### Example 1: Peak Analysis with Scripts

1. Import the data file Waterfall.dat under <Origin EXE folder>\Samples\Graphing folder with the associated import filter into the workbook Waterfall.
2. // Create a newbook and name it Waterfall (both long and short name)
newbook name:="Waterfall" option:=lsname;
// Define the file name and filter name
string fname$= system.path.program$ + "Samples\Graphing\Waterfall.dat";
string filtername$= "waterfall.oif"; // Use the impfile x-function to import the specified file with the import filter impfile fname:=fname$ filtername:=filtername$location:=data orng:=[Waterfall]1!; 3. Use a loop and the subtract_line X-Function to subtract a simple baseline of end points connection. 4. //Create new sheet named as SubtractedData newsheet name:=SubtractedData; //Define the newly created worksheet(current active) as a range variable range sdwk = !; //Active the "Waterfall" worksheet by its name page.active$ = "Waterfall";
//Define an integer to hold the number of columns in Waterfall sheet
int nc = wks.nCols;

//Find out the columns for excitation wavelength = 600, 610, 620, 630 ect
//Use the loop and subtract_line x-function to subtract baseline
//The first and last data points are found and connected linearly
//This line will be subtracted as baseline from source data
//Subtracted data will be named by excitation wavelength of source data
int nexc;
loop(ii, 2, nc)
{
range ry = [Waterfall]Waterfall!col($(ii)); int nWave = %(ry[D1]$);
if (mod(nWave, 10)==0)
{
nexc = nexc + 1;
range rx = [Waterfall]Waterfall!col(1);
range rr = [Waterfall]SubtractedData!(1,$(nexc)); subtract_line iy:=ry x1:=rx /* Specifies the X value of the first point*/ y1:=ry /* Specifies the Y value of the first point*/ x2:=rx[$(wks.maxRows)] /* Specifies the X value of the last point*/
y2:=ry[$(wks.maxRows)] /* Specifies the Y value of the last point*/ oy:=rr; //Rename the column long names in SubtractedData sheet //Use the User Defined Parameter Wavelength in Waterfall sheet rr[L]$ = ry[D1]$; //add a new column for next loop wks.addcol(); } else { continue; } } 5. Create new sheet for summary report 6. // Create new sheet for summary report and define ranges newsheet cols:=7 xy:="XYYYYYY" name:="Summary"; range rWaveLength = 1, rCntrInd = 2, rLtInd =3, rRtInd = 4; range rArea = 5, rCntr = 6, rHt = 7, rFWHM = 8; rWaveLength[L]$ = "WaveLength";
rCntrInd[L]$= "Peak Center Index"; rLtInd[L]$   = "Peak Left Index";
rRtInd[L]$= "Peak Right Index"; rArea[L]$    = "Peak Area";
rCntr[L]$= "Peak Center"; rHt[L]$      = "Peak Height";
rFWHM[L]$= "FWHM"; 7. To calculate the quantities of the highest peak of the data, we should find the highest peak with the pkfind X-Function and then calculate the quantities of the peak with the integ1 X-Function 8.  //active the SubtractedData sheet page.active$="SubtractedData";

//add columns for temp results of the finded peaks
loop(cc, 1, 2)
{
wks.addcol();
};

loop(ii, 2, nexc)
{
//find the highest peak
range rData = col($(ii)); range pcenter=$(nexc+1), pleft= $(nexc+2), pright=$(nexc+3);
pkfind rData filter:=num value:= 1 ocenter:=pcenter oleft:=pleft oright:=pright; //find a highest peak

//copy the result from the temp columns to summary sheet
wrcopy iw:=SubtractedData ow:=Summary c1:=nexc+1 c2:=nexc+3 r1:=1 r2:=1 dc1:=2 dr1:= ii-1;

//compute the quantities of the highest peak with integ1
int n1 = pleft; //specify the peak left index
int n2 = pright; //specify the peak right index
range rint = rData[$(n1):$(n2)]; // range of data to be integrated
double aa, cc, hh, fw;
integ1 iy:=rint area:=aa x0:=cc y0:=hh dx:=fw oy:=<optional>;
//put the quantities to summary sheet
rArea[$(ii-1)] = aa; rCntr[$(ii-1)] = cc;
rHt[$(ii-1)] = hh; rFWHM[$(ii-1)] =fw;
//copy the longname of calculated data to summary sheet
rWaveLength[$(ii-1)] = %(rData[L]$);
}
9. Create a graph of the quantities as a function of excitation wavelength with the plotxy X-Function
10. //create a graph of the quantities as a function of excitation wavelength
plotxy iy:=(rWaveLength, rArea) plot:=202 ogl:=[<new>];
plotxy iy:=(rWaveLength, rHt) plot:=202 ogl:=[<new>];
plotxy iy:=(rWaveLength, rFWHM) plot:=202 ogl:=[<new>];

### Example 2: Running Batch Processing with pre-saved Theme

1. Drag and drop the prepared theme,0-PA-BatchPA.ois, under the <Origin EXE folder>\Samples\Batch Processing folder into Origin.
2. Open the project file with data for peak analysis
3. // Open an Origin Project file
string fname$= system.path.program$ + "Samples\Batch Processing\Batch Peak Analysis.opj";
doc -o %(fname\$);   // Abbreviation of ''document -open''
4. Perform the peak analysis batch processing with the pre-saved theme with the pamultiY X-Function
5. paMultiY iy:=2:end theme:="BatchPA" append:=4 dataid:="My Parameter";