【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.23.2.16 ocmath_test_peaks_by_number
Contents
Description
Find the npeakNum highest peaks.
Syntax
int ocmath_test_peaks_by_number( int nSize, double * pXPeaks, double * pYPeaks, int * pnIndices, int npeakNum )
Parameters
- nSize
- [input] size of pXPeaks, pYPeaks, pnIndices;
- pXPeaks
- [modify] Its size is nSize. on input, it contains all peaks' X coordinate's datas; on output, it contains X coordinate's datas of the right peaks needed by user, if number of the right peaks is less than nSize, fill the excrescent elements of it with NANUM.
- pYPeaks
- [modify] Its size is nSize. on input, it contains all peaks' Y coordinate's datas; on output, it contains y coordinate's datas of the right peaks needed by user, if number of the right peaks is less than nSize, fill the excrescent elements of it with NANUM.
- pnIndices
- [modify] Its size is nSize. On input, it contains all peaks' indices; on output, it contains indices of the right peaks needed by user, and if number of the right peaks is less than nSize, fill the excrescent elements of it with 0.
- npeakNum
- [input] the number 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_number_ex1( ) { GraphLayer gl = Project.ActiveLayer(); if (!gl) { 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 peakNum=10; int nRet = ocmath_test_peaks_by_number(nDataSize, vxPeaks, vyPeaks, vnIndices, peakNum); if( nRet < OE_NOERROR ) { printf("error code: %d\n", nRet); return; } vxPeaks.SetSize(peakNum); vyPeaks.SetSize(peakNum); vnIndices.SetSize(peakNum); //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 npeakNum highest peaks depending on the abs of points y value.
In other words, find npeakNum peaks, whose y value's abs is greatest in the residual peaks.
Then, nPeakNum records the number of peaks passed the 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
Header to Include
origin.h