2.1.23.2.2 ocmath_create_baseline_by_masking_peaks


Description

Create curve's baseline by masking its peaks.

Syntax

int ocmath_create_baseline_by_masking_peaks( UINT lDataSize, const double * px, const double * py, UINT lBaselinePoints, double * pxb, double * pyb, DWORD dwCtrl = POSITIVE_DIRECTION )

Parameters

lDataSize
[input] size of px, py
px
[input] it contains curve's X coordinate's datas
py
[input] it contains curve's Y coordinate's datas
lBaselinePoints
[input] size of pxb, pyb
pxb
[output] X coordinate's datas of baseline
pyb
[output] Y coordinate's datas of baseline
dwCtrl
[input]
BOTH_DIRECTION: find peaks in both direction
NEGATIVE_DIRECTION: only find peaks in negative direction
POSITIVE_DIRECTION: only find peaks in positive direction

Return

Return OE_NOERROR if succeed, otherwise, non-zero error code is returned.

Examples

EX1

//Assume the active layer is a graph with at least one data plots. This piece of
//code get the data in the first data plot to create baseline. The result is 
//output into a new worksheet.
void ocmath_create_baseline_by_masking_peaks_ex1()
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        return;
    }
    
    //Get plot data from the first data plot
    DataPlot dp = gl.DataPlots(0);        
    DataRange dr;
    vector vxData, vyData;
    if(dp.GetDataRange(dr))
    {
        DWORD dwPlotID;
        if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vyData, &vxData) < 0)
        {
            printf("get_plot_data failed GetData");
            return;
        }
    }
 
    uint nDataSize = vxData.GetSize();
 
    vector vxb, vyb;
    vxb.SetSize(nDataSize);
    vyb.SetSize(nDataSize);
    int nRet=ocmath_create_baseline_by_masking_peaks(nDataSize, vxData, vyData, nDataSize, vxb, vyb, POSITIVE_DIRECTION | NEGATIVE_DIRECTION);
    if( nRet < OE_NOERROR )
    {
        printf("error code: %d\n", nRet);
        return;
    }
    
    //New a worksheet and put the result in it
    WorksheetPage wksPage;
    wksPage.Create();
    Worksheet wksResult = wksPage.Layers(0);
    //wksResult.AddCol("Indices");
    int nXCol, nYCol;
    nXCol = wksResult.AddCol("X");
    nYCol = wksResult.AddCol("Y");
    //wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(1).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Y);

    DataRange drOut;
    drOut.Add("X", wksResult, 0, nXCol, -1, nXCol);
    drOut.Add("Y", wksResult, 0, nYCol, -1, nYCol);
    drOut.SetData(&vyb, &vxb);
    
    //plot the baseline
    gl.AddPlot(drOut, IDM_PLOT_LINE);
}

Remark

Create curve's baseline by masking its peaks.

First, use ocmath_find_peaks_1st_derivative to find curve's peaks, then according to every peak, use ocmath_find_peaks_partition to find its partition, which recorded in nStart and nEnd.

At last, use the two end points of every peak's partition to interpolate the baseline between nStart and nEnd.

lBaselinePoints records the number of baseline, pxb and pyb contain X and Y coordinate's datas of baseline

See Also

ocmath_find_peaks_1st_derivative, ocmath_find_peaks_partition, ocmath_init_baseline_by_connect_ends

Header to Include

origin.h

Reference