【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.23.2.11 ocmath_find_peaks_by_search_window
Contents
Description
Find peaks in local scope.
Syntax
int ocmath_find_peaks_by_search_window( UINT * lSize, const double * pX, const double * pY, double * pXPeaks, double * pYPeaks, int * pnIndices, int nDir, double dSearchWidth, double dSearchHeight )
Parameters
- lSize
- [modify] on input, size of pX, pY, pXPeaks, pYPeaks, pnIndices; on output, return number of peaks
- pX
- [input] it contains curve's X coordinate's datas
- pY
- [input] it contains curve's Y coordinate's datas
- pXPeaks
- [output] Its size is equal to the size of px. it contains peaks' X coordinate's datas,
- if the number of peaks is less than its size, the excrescent elements of it are filled
- with 0.
- pYPeaks
- [output] Its size is equal to the size of py. it contains peaks' Y coordinate's datas,
- if the number of peaks is less than its size, the excrescent elements of it are filled
- with 0.
- pnIndices
- [output] Its size is equal to the size of px. it contains peaks' indices, if peaks's number is less than its size, the excrescent elements of it are filled with 0.
- nDir
- [input]
- BOTH_DIRECTION: find peaks in both direction
- NEGATIVE_DIRECTION: only find peaks in negative direction
- POSITIVE_DIRECTION: only find peaks in positive direction
- dSearchWidth
- [input] window x axle size, defines local peak's x axle scope.
- dSearchHeight
- [input] window y axle size, defines local peak's y axle scope.
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 and find the peaks. //The result is output in a new worksheet and the feets will plot in the original //data plot. void ocmath_find_peaks_by_search_window_ex1( ) { GraphLayer gl = Project.ActiveLayer(); if (!gl) { return; } //get datas 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(); int iSize = vxData.GetSize(); vector vxPeaks, vyPeaks; vector<int> vnIndices; vxPeaks.SetSize(nDataSize); vyPeaks.SetSize(nDataSize); vnIndices.SetSize(nDataSize); int nRet = ocmath_find_peaks_by_search_window( &nDataSize, vxData, vyData, vxPeaks, vyPeaks, vnIndices, POSITIVE_DIRECTION | NEGATIVE_DIRECTION, 11, 20); if( nRet < OE_NOERROR ) { printf("error code: %d\n", nRet); return; } vxPeaks.SetSize(nDataSize); vyPeaks.SetSize(nDataSize); vnIndices.SetSize(nDataSize); //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 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
First, find local maximum point in a local scope selected by nSearchWidth. For a current point marked by nIndex, the scope is [nIndex-nLocalPts, nIndex+nLocalPts], where nLocalPts equals nSearchWidth/2+1.
If differences between y coordinates of the local maximum point and the two scope bound points are larger than nSearchHeight, the local maximum point will be save as a peak.
See Also
ocmath_find_peaks_by_local_maximum
Header to Include
origin.h