2.1.23.2.15 ocmath_test_peaks_by_height


Description

Test and record the number of peaks passed testing.

Syntax

int ocmath_test_peaks_by_height( int * nPeakNum, double * pXPeaks, double * pYPeaks, int * pnIndices, double dMinHeight )

Parameters

nPeakNum
[modify] on input, size of pXPeaks, pYPeaks, pnIndices; on output the number of peaks whose height greater than dMinHeight
pXPeaks
[modify] Its size is equal to the input nPeakNum. on input, it contains all peaks' X coordinate's datas; on output, it contains X coordinate's datas of peaks whose height greater than dMinHeight, if number of the right peaks is less than its size, fill the excrescent elements of it with NANUM.
pYPeaks
[modify] Its size is equal to the input nPeakNum. on input, it contains all peaks' Y coordinate's datas; on output, it contains y coordinate's datas of peaks whose height greater than dMinHeight, if number of the right peaks is less than its size, fill the excrescent elements of it with NANUM.
pnIndices
[modify] Its size is equal to the input nPeakNum. on input, it contains all peaks' indices, on output, it contains indices of the right peaks, which passed the testing. if number of the right peaks is less than its size, fill the excrescent elements of it with 0.
dMinHeight
[input] the minimum height of peaks needed by user

Return

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

Examples

EX1

//Assume in the current graph, curve's XY data is in the first data plot. This piece
//of code get the XY data of the curve from the first data plot, use  
//ocmath_find_peaks_1st_derivative to find the curve's peaks and then test the peaks.
//The result is output in a new worksheet and the peaks will plot in the original 
//data plot.
void ocmath_test_peaks_by_height_ex1( )
{
    GraphLayer gl = Project.ActiveLayer();
    if (!gl)
    {
        out_str("Active layer is not a graph.");
        return;
    }
 
    //get data from the first dataplot
    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 vxPeaks, vyPeaks;
    vector<int> vnIndices;
 
    vxPeaks.SetSize(nDataSize);
    vyPeaks.SetSize(nDataSize);
    vnIndices.SetSize(nDataSize);
 
    //Find curve's peaks by 1st derivative. 
    ocmath_find_peaks_1st_derivative( &nDataSize, vxData, vyData, vxPeaks, vyPeaks, vnIndices, POSITIVE_DIRECTION | NEGATIVE_DIRECTION,11);
    
    vxPeaks.SetSize(nDataSize);
    vyPeaks.SetSize(nDataSize);
    vnIndices.SetSize(nDataSize);
    int nPeakNum = nDataSize;
    double dMinHeight = 10;
    int nRet=ocmath_test_peaks_by_height( &nPeakNum, vxPeaks, vyPeaks, vnIndices,dMinHeight);
 
    if( nRet < OE_NOERROR )
    {
        printf("error code: %d\n", nRet);
        return;
    }
    vxPeaks.SetSize(nPeakNum);
    vyPeaks.SetSize(nPeakNum);
    vnIndices.SetSize(nPeakNum);
    
    //new a worksheet to output the result
    WorksheetPage wksPage;
    wksPage.Create();
    Worksheet wksResult = wksPage.Layers(0);
    int nIndCol, nXCol, nYCol;
    nIndCol = wksResult.AddCol("Indices");
    nXCol = wksResult.AddCol("X Coordinate");
    nYCol = wksResult.AddCol("Y Coordinate");
    wksResult.Columns(nIndCol).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(nXCol).SetType(OKDATAOBJ_DESIGNATION_X);
    wksResult.Columns(nYCol).SetType(OKDATAOBJ_DESIGNATION_Y);
    
    DataRange drOut;
    drOut.Add("X", wksResult, 0, nIndCol, -1, nIndCol);
    drOut.Add("Y", wksResult, 0, nXCol, -1, nXCol);
    drOut.Add("Z", wksResult, 0, nYCol, -1, nYCol);
    drOut.SetData(&vyPeaks, &vxPeaks, &vnIndices);
    
    //plot the peaks in the data plot
    XYRange plotRange;
    plotRange.Add("X", wksResult, 0, nXCol, -1, nXCol);
    plotRange.Add("Y", wksResult, 0, nYCol, -1, nYCol);
    gl.AddPlot(plotRange, IDM_PLOT_SCATTER);
}

Remark

Find the peaks, which are higher than dMinHeight, i.e. their y value's abs greater than dMinHeight.

Then, nPeakNum records the number of peaks passed testing, pXPeaks and pYPeaks contain X and Y coordinate's datas of peaks passed the testing, pnIndices contains the indices of peaks passed testing.

See Also

ocmath_test_peaks_by_number

Header to Include

origin.h

Reference