# smooth

## Description

Smooth a curve or a numeric vector using Adjacent Averaging, FFT, Savitzky-Golay or Median filter.

## Syntax

bool smooth( vector & vY, int imethod = 0, int ileftpts = 3, int irightpts = 3, int ipolydeg = 2 )

bool smooth(Curve &crv, int imethod = 0, int ileftpts = 3, int irightpts = 3, int ipolydeg = 2)


## Parameters

vY
[modify] input data to be smoothed.
imethod
[input] method: Adjacent Averaging (default 0), FFT (1), Savitzky-Golay (2), or Median(3).
ileftpts
[input] left points (default is 3).
irightpts
[input] right points (default is 3, Savitzky-Golay only).
ipolydeg
[input] degree of polynomial (default is 2, Savitzky-Golay only).

crv
[modify] Origin C Curve object
imethod
[input] method: Adjacent Averaging (default 0), FFT (1), Savitzky-Golay (2), or Median(3).
ileftpts
[input] left points (default is 3).
irightpts
[input] right points (default is 3, Savitzky-Golay only).
ipolydeg
[input] degree of polynomial (default is 2, Savitzky-Golay only).

## Return

Returns TRUE on success and FALSE on failure.

## Examples

EX1

// This example will return the result like following:
//    Smoothing on Data4_B succeeded.
//    Method=0, LeftPts=2
// And the data in the 3rd column will be :
/*
0.097
0.25288
0.37823
0.32324
0.45531
0.44601
0.44514
*/
void smooth_ex1()
{
int Method, ADJAV = 0 , FFT = 1 , SG = 2; // Method types
int LPts;     // Points at left
int RPts, PolyDeg ; // Paramethers only for S-G
BOOL rc;

Worksheet wks;
wks.Create();
String wksName=wks.GetPage().GetName();
Dataset myXDs(wks,0);
Dataset myYDs(wks,1);
String strYName = myYDs.GetName();
Dataset mySmooth(wks,2);    // Target of smoothing operation

//******* Create sample data *****************
myXDs.SetSize(7);
myYDs.SetSize(7);
mySmooth.SetSize(7);
myXDs=1;    myYDs=0.097;     mySmooth=myYDs;
myXDs=2;    myYDs=0.41256;    mySmooth=myYDs;
myXDs=3;    myYDs=0.24909;    mySmooth=myYDs;
myXDs=4;    myYDs=0.47304;    mySmooth=myYDs;
myXDs=5;    myYDs=0.2476;    mySmooth=myYDs;
myXDs=6;    myYDs=0.64529;    mySmooth=myYDs;
myXDs=7;    myYDs=0.44514;    mySmooth=myYDs;
//******** End of Sample Data Creation *******

LPts=2;
RPts=0;
PolyDeg=0;
Curve myCrv(wks,0,2);

rc = smooth(myCrv, Method, LPts, RPts, PolyDeg);  // Demonstration of smooth

if(rc)
{
if(Method==SG)
printf("Smoothing on %s succeeded.\n  Method=%d, LeftPts=%d, RightPts=%d, PolyOrder=%d\n",
strYName, Method, LPts, RPts, PolyDeg);
else
printf("Smoothing on %s succeeded.\n  Method=%d, LeftPts=%d\n",
strYName, Method, LPts);
}
else
printf("Error: Smoothing failed.\n",rc);
}


EX2

// This example will return the result like following:
/*
Smoothing successfully, with result as :
0.097000
0.252883
0.378230
0.323243
0.455310
0.446010
0.445140
*/
void smooth_ex2()
{
//******* Create sample data *****************
vector vY;
vY.SetSize(7);
vY=0.097;
vY=0.41256;
vY=0.24909;
vY=0.47304;
vY=0.2476;
vY=0.64529;
vY=0.44514;;
//******** End of Sample Data Creation *******
int Method = 0; //Adjacent Averaging
int LPts=2; // Points at left
int RPts=0;// Paramethers only for S-G
int PolyDeg=0;

bool bRet = smooth(vY, Method, LPts, RPts, PolyDeg);  // Demonstration of smooth
if ( bRet )
{
out_str("Smoothing successfully, with result as :");
for ( int ii = 0; ii < vY.GetSize(); ii++ )
{
printf("%lf\n", vY[ii]);
}
}
else
out_str("Smoothing fails.");

}


## Remark

Smooth a vector using Adjacent Averaging, FFT, Savitzky-Golay or Median filter.