smoothing. have 3 methods: median filter, Savitzky-Golay smoothing and adjacent averaging smoothing.
int ocmath_smooth( int nSize, const double * pY, double * pSmooth, int nLeftpts, int nMethod = SMOOTH_SG, int nBoundary = EDGEPAD_NONE, int nRightpts = -1, int nPolydeg = 2, int nDervOrder = 0, double dPercent = 50, bool bWeight = false, bool bAveraging = false )
- [input] vector size of both pY and pSmooth
- [input] pointer to Y vector data.
- [output] pointer to smoothed data, or derivatives, depending on nDervOrder(only for Savitzky-Golay smoothing).
- [input] if do Savitzky-Golay smoothing,number of data points to the left to be used in filter convolution,
- if do median filter, Number of surrounding points to left and right. Thus the number of points considered in each segment is (2*nPts + 1).
- if do adjacent averaging smoothing, is the window's size.
- [input] smoothing method.
- SMOOTH_ADJAVE adjacent averaging smoothing
- SMOOTH_SG Savitzky-Golay smoothing
- SMOOTH_MEDIAN_FILTER median filter
- [input] data are padded on both ends. Possible values are
- EDGEPAD_NONE no padding
- EDGEPAD_REFLECT pad reflect, end points are repeated such that on the left, [-1] = , [-2] = , [-3] =  and etc
- EDGEPAD_REPEAT pad with  values the left and with [nSize-1] on the right
- EDGEPAD_EXTRAPOLATE linear extrapolation using nLeft points on the left and nRight points on the right
- EDGEPAD_PERIODIC pad periodic, [-1] = [nSize -1], [-2] = [nSize - 2]
- [input] for Savitzky-Golay smoothing. number of data points to the right to be used in filter convolution, default (-1) will assume nLeft.
- Total number of points used in the polynomial fits are (nLeft + nRight + 1) and it must be odd, namely nLeft + nRight must be even.
- [input] for Savitzky-Golay smoothing.The polynomial order. Higher order will preserve sharper features. nPolyDeg must be less then (nLeft + nRight + 1).
- [input] for Savitzky-Golay smoothing. order of derivative desired (0 = smoothing). To generate a fourth derivative, a minimum quartic (order 4) smoothing must be used.
- For a third derivative, a minimum cubic (order 3) smoothing is needed. Similarly, a second derivative requires a minimum quadratic (order 2) smoothing.
- [input] for median filter.The percent for computing median.
- [input] for adjacent averaging smoothing. weight smooth or not. default is not(FALSE)
- [input] for median filter.If true, the function will average the most nearest neighbors if there is no match to the given percent.
OE_NOERROR for success
//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 smooth on it.
//The result is output in a new worksheet and the smoothing curve will plot in the
//original data plot with color red.
GraphLayer gl = Project.ActiveLayer();
out_str("Active layer is not a graph.");
//get XY data from the first dataplot
DataPlot dp = gl.DataPlots(0);
vector vx, vy;
if(dr.GetData(DRR_GET_DEPENDENT | DRR_NO_FACTORS, 0, &dwPlotID, NULL, &vy, &vx) < 0)
printf("get data failed GetData");
//do Savitzky-Golay smoothing, Left=Right=7, quadratic
int nRet = ocmath_smooth(vy.GetSize(), vy, vSmooth, 3,SMOOTH_SG, EDGEPAD_NONE, 3, 2);
//new a worksheet to put the result
drOut.Add("X", wks, 0, 0, -1, 0);
drOut.Add("Y", wks, 0, 1, -1, 1);
//plot the curve after smoothing
int nPlot = gl.AddPlot(drOut, IDM_PLOT_LINE);
dp = gl.DataPlots(nPlot);
header to Include