Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/05/11 13:59:23 (13 years ago)
Author:
gkronber
Message:

#1623 extended Savitzky-Golay filter command to support the calculation of smoothed derivatives of time series.

Location:
branches/HeuristicLab.DataImporter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.DataImporter

    • Property svn:ignore
      •  

        old new  
        11*.suo
         2_ReSharper.HeuristicLab.DataImporter
  • branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/ChangeValues/FilterSavitzkyGolayCommand.cs

    r6134 r6706  
    4545    public int Order { get; set; }
    4646
     47    public int OrderOfDerivative { get; set; }
     48
    4749    private FilterSavitzkyGolayCommand()
    4850      : base(null, string.Empty, null) {
     
    5658      this.WindowRight = 16;
    5759      this.Order = 2;
     60      this.OrderOfDerivative = 0;
    5861    }
    5962
     
    7780          column = (DoubleColumn)ColumnGroup.GetColumn(col);
    7881          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));
    8083        }
    8184      }
     
    97100    }
    98101
    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) {
    100103      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);
    102105
    103106      DoubleColumn newCol = (DoubleColumn)oldColumn.CreateCopyOfColumnWithoutValues();
     
    117120    /// <param name="nl">number of samples to the left</param>
    118121    /// <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>
    120124    /// <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) {
    122126      int np = nl + nr + 1;
    123       int ld = 0;
    124       int m = order;
    125127
    126128      int j, k, imj, ipj, kk, mm;
    127129      double fac = 0;
    128130      double sum = 0;
    129       if (np < 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();
    130132
    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];
    134135      c = new double[np];
    135136
    136       for (ipj = 0; ipj <= (m << 1); ipj++) {
     137      for (ipj = 0; ipj <= (order << 1); ipj++) {
    137138        sum = (ipj > 0 ? 0.0 : 1.0);
    138139        for (k = 1; k <= nr; k++) sum += Math.Pow((double)k, (double)ipj);
    139140        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);
    141142        for (imj = -mm; imj <= mm; imj += 2)
    142143          a[(ipj + imj) / 2, (ipj - imj) / 2] = sum;
    143144      }
    144       for (j = 0; j < m + 1; j++) b[j] = 0;
     145      for (j = 0; j < order + 1; j++) b[j] = 0;
    145146      b[ld] = 1.0;
    146147      alglib.densesolverreport rep;
     
    153154        sum = x[0];
    154155        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);
    156157        kk = k + nl;
    157158        c[kk] = sum;
Note: See TracChangeset for help on using the changeset viewer.