2.1.23.2.6 ocmath_find_markers_of_peaks_by_height_and_width
Description
Find feets of the peaks with user settings.
Syntax
int ocmath_find_markers_of_peaks_by_height_and_width( UINT lSize, const double * px, const double * py, int nPeakNum, const int * pPeakIndices, int nMarkersNum, int * pMarkersIndices, double dMarkerHeight, double dMaxWidth, double dMinWidth )
Parameters
- lSize
- [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
- nPeakNum
- [input] size of pPeakIndices
- pPeakIndices
- [input] the indices of peaks, the indices must be monotonously ascending
- nMarkersNum
- [input] size of pMarkersIndices, its initial value should larger than 2*nPeakNum
- pMarkersIndices
- [output] the indices of peaks' feets, its initial size is nMarkersNum, if nMarkersNum is more than 2*nPeakNum, fill the excrescent elements with NANUM after pMarkersIndices[2*nPeakNum-1]
- dMarkerHeight
- [input] the estimated feet height of peaks, which will be marked
- dMaxWidth
- [input] the maximum width of peaks, which will be marked
- dMinWidth
- [input] the minimum width of peaks, which will be marked
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 feets of
//the peaks. The result is output in a new worksheet and the feets will plot in the
//original data plot.
void ocmath_find_markers_of_peaks_by_height_and_width_ex1( )
{
GraphLayer gl = Project.ActiveLayer();
if (!gl)
{
return;
}
//Get data of curve 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 vxPeaks, vyPeaks;
vector<int> vnIndices;
vxPeaks.SetSize(nDataSize);
vyPeaks.SetSize(nDataSize);
vnIndices.SetSize(nDataSize);
ocmath_find_peaks_1st_derivative( &nDataSize, vxData, vyData, vxPeaks, vyPeaks, vnIndices, POSITIVE_DIRECTION | NEGATIVE_DIRECTION, false);
vxPeaks.SetSize(nDataSize);
vyPeaks.SetSize(nDataSize);
vnIndices.SetSize(nDataSize);
int lSize = vxData.GetSize();
int peakNum=vnIndices.GetSize();
double dMarkerHeight = 30;
double dMaxWidth=30;
double dMinWidth=20;
vector<int> markeIndices;
markeIndices.SetSize(2*peakNum);
int nRet = ocmath_find_markers_of_peaks_by_height_and_width(lSize, vxData, vyData, peakNum, vnIndices,2*peakNum, markeIndices, dMarkerHeight, dMaxWidth,dMinWidth);
if( nRet < OE_NOERROR )
{
printf("error code: %d\n", nRet);
return;
}
vector vxMarker, vyMarker;
int nSize = markeIndices.GetSize();
vxMarker.SetSize(nSize);
vyMarker.SetSize(nSize);
for(int ii = 0; ii < markeIndices.GetSize(); ii++)
{
if(markeIndices[ii] > 0)
{
vxMarker[ii] = vxData[markeIndices[ii]-1];
vyMarker[ii] = vyData[markeIndices[ii]-1];
}
else
{
vxMarker[ii] = NANUM;
vyMarker[ii] = NANUM;
}
}
vxMarker.Trim();
vyMarker.Trim();
//new a worksheet to output the result
WorksheetPage wksPage;
wksPage.Create();
Worksheet wksResult = wksPage.Layers(0);
//wksResult.AddCol("Indices");
int nXCol, nYCol;
nXCol = wksResult.AddCol("Marker X");
nYCol = wksResult.AddCol("Marker Y");
//wksResult.Columns(0).SetType(OKDATAOBJ_DESIGNATION_X);
wksResult.Columns(1).SetType(OKDATAOBJ_DESIGNATION_X);
wksResult.Columns(2).SetType(OKDATAOBJ_DESIGNATION_Y);
//scatter plot of the feets
DataRange drOut;
drOut.Add("X", wksResult, 0, nXCol, -1, nXCol);
drOut.Add("Y", wksResult, 0, nYCol, -1, nYCol);
drOut.SetData(&vyMarker, &vxMarker);
gl.AddPlot(drOut, IDM_PLOT_SCATTER);
}
Remark
Find feets of the peaks, whose height is greater than dMarkerHeight( means abs of the points' y values are greater than dMarkerHeight) and width is between dMinWidth and dMaxWidth, then record peaks' left and right feets in pMarkersIndices.
pMarkersIndices contains the indices of peaks' feets.
See Also
ocmath_find_peaks_1st_derivative, ocmath_find_peaks_2nd_derivative
Header to Include
origin.h
Reference
|