Changeset 6706 for branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/FilterSavitzkyGolayCommand.cs
- Timestamp:
- 09/05/11 13:59:23 (13 years ago)
- Location:
- branches/HeuristicLab.DataImporter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.DataImporter
- Property svn:ignore
-
old new 1 1 *.suo 2 _ReSharper.HeuristicLab.DataImporter
-
- Property svn:ignore
-
branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/FilterSavitzkyGolayCommand.cs
r6134 r6706 45 45 public int Order { get; set; } 46 46 47 public int OrderOfDerivative { get; set; } 48 47 49 private FilterSavitzkyGolayCommand() 48 50 : base(null, string.Empty, null) { … … 56 58 this.WindowRight = 16; 57 59 this.Order = 2; 60 this.OrderOfDerivative = 0; 58 61 } 59 62 … … 77 80 column = (DoubleColumn)ColumnGroup.GetColumn(col); 78 81 oldColumns.Add(col, column); 79 ColumnGroup.ReplaceColumn(col, CalcNewColumn(column, this.WindowLeft, this.WindowRight, this.Order ));82 ColumnGroup.ReplaceColumn(col, CalcNewColumn(column, this.WindowLeft, this.WindowRight, this.OrderOfDerivative, this.Order)); 80 83 } 81 84 } … … 97 100 } 98 101 99 private DoubleColumn CalcNewColumn(DoubleColumn oldColumn, int windowLeft, int windowRight, int order) {102 private DoubleColumn CalcNewColumn(DoubleColumn oldColumn, int windowLeft, int windowRight, int derivativeOrder, int order) { 100 103 double[] c; 101 SavitzkyGolay(Math.Abs(windowLeft), Math.Abs(windowRight), order, out c);104 SavitzkyGolay(Math.Abs(windowLeft), Math.Abs(windowRight), derivativeOrder, order, out c); 102 105 103 106 DoubleColumn newCol = (DoubleColumn)oldColumn.CreateCopyOfColumnWithoutValues(); … … 117 120 /// <param name="nl">number of samples to the left</param> 118 121 /// <param name="nr">number of samples to the right</param> 119 /// <param name="m">order of the polynomial to fit</param> 122 /// <param name="ld">order of derivative (smoothing=0)</param> 123 /// <param name="order">order of the polynomial to fit</param> 120 124 /// <param name="c">resulting coefficients for convolution, in correct order (t-nl, ... t-1, t+0, t+1, ... t+nr)</param> 121 private void SavitzkyGolay(int nl, int nr, int order, out double[] c) {125 private void SavitzkyGolay(int nl, int nr, int ld, int order, out double[] c) { 122 126 int np = nl + nr + 1; 123 int ld = 0;124 int m = order;125 127 126 128 int j, k, imj, ipj, kk, mm; 127 129 double fac = 0; 128 130 double sum = 0; 129 if (n p < nl + nr + 1 || nl < 0 || nr < 0 || ld > m || nl + nr < m) throw new ArgumentException();131 if (nl < 0 || nr < 0 || ld > order || nl + nr < order) throw new ArgumentException(); 130 132 131 int[] indx = new int[m + 1]; 132 double[,] a = new double[m + 1, m + 1]; 133 double[] b = new double[m + 1]; 133 double[,] a = new double[order + 1, order + 1]; 134 double[] b = new double[order + 1]; 134 135 c = new double[np]; 135 136 136 for (ipj = 0; ipj <= ( m<< 1); ipj++) {137 for (ipj = 0; ipj <= (order << 1); ipj++) { 137 138 sum = (ipj > 0 ? 0.0 : 1.0); 138 139 for (k = 1; k <= nr; k++) sum += Math.Pow((double)k, (double)ipj); 139 140 for (k = 1; k <= nl; k++) sum += Math.Pow((double)-k, (double)ipj); 140 mm = Math.Min(ipj, 2 * m- ipj);141 mm = Math.Min(ipj, 2 * order - ipj); 141 142 for (imj = -mm; imj <= mm; imj += 2) 142 143 a[(ipj + imj) / 2, (ipj - imj) / 2] = sum; 143 144 } 144 for (j = 0; j < m+ 1; j++) b[j] = 0;145 for (j = 0; j < order + 1; j++) b[j] = 0; 145 146 b[ld] = 1.0; 146 147 alglib.densesolverreport rep; … … 153 154 sum = x[0]; 154 155 fac = 1.0; 155 for (mm = 1; mm <= m; mm++) sum += x[mm] * (fac *= k);156 for (mm = 1; mm <= order; mm++) sum += x[mm] * (fac *= k); 156 157 kk = k + nl; 157 158 c[kk] = sum;
Note: See TracChangeset
for help on using the changeset viewer.