【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.22.4.6 smooth
Contents
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(); wks.AddCol("Smoothed"); // Add a column to backup the original Dataset mySmooth(wks,2); // Target of smoothing operation //******* Create sample data ***************** myXDs.SetSize(7); myYDs.SetSize(7); mySmooth.SetSize(7); myXDs[0]=1; myYDs[0]=0.097; mySmooth[0]=myYDs[0]; myXDs[1]=2; myYDs[1]=0.41256; mySmooth[1]=myYDs[1]; myXDs[2]=3; myYDs[2]=0.24909; mySmooth[2]=myYDs[2]; myXDs[3]=4; myYDs[3]=0.47304; mySmooth[3]=myYDs[3]; myXDs[4]=5; myYDs[4]=0.2476; mySmooth[4]=myYDs[4]; myXDs[5]=6; myYDs[5]=0.64529; mySmooth[5]=myYDs[5]; myXDs[6]=7; myYDs[6]=0.44514; mySmooth[6]=myYDs[6]; //******** End of Sample Data Creation ******* Method=ADJAV; 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]=0.097; vY[1]=0.41256; vY[2]=0.24909; vY[3]=0.47304; vY[4]=0.2476; vY[5]=0.64529; vY[6]=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.
See Also
Header to Include
origin.h