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:
4 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;
  • branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/View/FilterSavitzkyGolayCommandView.Designer.cs

    r6134 r6706  
    5151      this.label3 = new System.Windows.Forms.Label();
    5252      this.numOrder = new System.Windows.Forms.NumericUpDown();
     53      this.numOrderOfDerivative = new System.Windows.Forms.NumericUpDown();
     54      this.label4 = new System.Windows.Forms.Label();
    5355      ((System.ComponentModel.ISupportInitialize)(this.numWindowLeft)).BeginInit();
    5456      ((System.ComponentModel.ISupportInitialize)(this.numWindowRight)).BeginInit();
    5557      ((System.ComponentModel.ISupportInitialize)(this.numOrder)).BeginInit();
     58      ((System.ComponentModel.ISupportInitialize)(this.numOrderOfDerivative)).BeginInit();
    5659      this.SuspendLayout();
    5760      //
     
    7174      this.numWindowLeft.Name = "numWindowLeft";
    7275      this.numWindowLeft.Size = new System.Drawing.Size(120, 20);
    73       this.numWindowLeft.TabIndex = 0;
     76      this.numWindowLeft.TabIndex = 1;
    7477      this.numWindowLeft.Value = new decimal(new int[] {
    7578            4,
     
    8588      this.label1.Name = "label1";
    8689      this.label1.Size = new System.Drawing.Size(101, 13);
    87       this.label1.TabIndex = 1;
     90      this.label1.TabIndex = 0;
    8891      this.label1.Text = "Window start offset:";
    8992      //
     
    9497      this.label2.Name = "label2";
    9598      this.label2.Size = new System.Drawing.Size(99, 13);
    96       this.label2.TabIndex = 3;
     99      this.label2.TabIndex = 2;
    97100      this.label2.Text = "Window end offset:";
    98101      //
     
    107110      this.numWindowRight.Name = "numWindowRight";
    108111      this.numWindowRight.Size = new System.Drawing.Size(120, 20);
    109       this.numWindowRight.TabIndex = 2;
     112      this.numWindowRight.TabIndex = 3;
    110113      this.numWindowRight.Value = new decimal(new int[] {
    111114            4,
     
    118121      //
    119122      this.label3.AutoSize = true;
    120       this.label3.Location = new System.Drawing.Point(8, 62);
     123      this.label3.Location = new System.Drawing.Point(9, 89);
    121124      this.label3.Name = "label3";
    122       this.label3.Size = new System.Drawing.Size(36, 13);
    123       this.label3.TabIndex = 4;
    124       this.label3.Text = "Order:";
     125      this.label3.Size = new System.Drawing.Size(100, 13);
     126      this.label3.TabIndex = 6;
     127      this.label3.Text = "Order of polynomial:";
    125128      //
    126129      // numOrder
    127130      //
    128       this.numOrder.Location = new System.Drawing.Point(115, 60);
     131      this.numOrder.Location = new System.Drawing.Point(115, 87);
    129132      this.numOrder.Maximum = new decimal(new int[] {
    130133            8,
     
    134137      this.numOrder.Name = "numOrder";
    135138      this.numOrder.Size = new System.Drawing.Size(120, 20);
    136       this.numOrder.TabIndex = 5;
     139      this.numOrder.TabIndex = 7;
    137140      this.numOrder.Value = new decimal(new int[] {
    138141            2,
     
    142145      this.numOrder.ValueChanged += new System.EventHandler(this.numOrder_ValueChanged);
    143146      //
     147      // numOrderOfDerivative
     148      //
     149      this.numOrderOfDerivative.Location = new System.Drawing.Point(115, 60);
     150      this.numOrderOfDerivative.Maximum = new decimal(new int[] {
     151            3,
     152            0,
     153            0,
     154            0});
     155      this.numOrderOfDerivative.Name = "numOrderOfDerivative";
     156      this.numOrderOfDerivative.Size = new System.Drawing.Size(120, 20);
     157      this.numOrderOfDerivative.TabIndex = 5;
     158      this.numOrderOfDerivative.ValueChanged += new System.EventHandler(this.numOrderOfDerivative_ValueChanged);
     159      //
     160      // label4
     161      //
     162      this.label4.AutoSize = true;
     163      this.label4.Location = new System.Drawing.Point(8, 62);
     164      this.label4.Name = "label4";
     165      this.label4.Size = new System.Drawing.Size(97, 13);
     166      this.label4.TabIndex = 4;
     167      this.label4.Text = "Order of derivative:";
     168      //
    144169      // FilterSavitzkyGolayCommandView
    145170      //
    146171      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    147172      this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
     173      this.Controls.Add(this.numOrderOfDerivative);
     174      this.Controls.Add(this.label4);
    148175      this.Controls.Add(this.numOrder);
    149176      this.Controls.Add(this.label3);
     
    154181      this.Name = "FilterSavitzkyGolayCommandView";
    155182      this.Padding = new System.Windows.Forms.Padding(5);
    156       this.Size = new System.Drawing.Size(244, 98);
     183      this.Size = new System.Drawing.Size(246, 117);
    157184      ((System.ComponentModel.ISupportInitialize)(this.numWindowLeft)).EndInit();
    158185      ((System.ComponentModel.ISupportInitialize)(this.numWindowRight)).EndInit();
    159186      ((System.ComponentModel.ISupportInitialize)(this.numOrder)).EndInit();
     187      ((System.ComponentModel.ISupportInitialize)(this.numOrderOfDerivative)).EndInit();
    160188      this.ResumeLayout(false);
    161189      this.PerformLayout();
     
    170198    private System.Windows.Forms.Label label3;
    171199    private System.Windows.Forms.NumericUpDown numOrder;
     200    private System.Windows.Forms.NumericUpDown numOrderOfDerivative;
     201    private System.Windows.Forms.Label label4;
    172202  }
    173203}
  • branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Command/View/FilterSavitzkyGolayCommandView.cs

    r6134 r6706  
    5353      get { return this.Command.Order; }
    5454    }
     55    public int OrderOfDerivative {
     56      get { return this.Command.OrderOfDerivative; }
     57    }
    5558
    5659    private void numWindowLeft_ValueChanged(object sender, System.EventArgs e) {
     
    6265    }
    6366
     67    private void numOrder_ValueChanged(object sender, EventArgs e) {
     68      this.UpdateCommand();
     69    }
     70
     71    private void numOrderOfDerivative_ValueChanged(object sender, EventArgs e) {
     72      this.UpdateCommand();
     73    }
     74
    6475    private void UpdateCommand() {
    6576      if (Command != null) {
     
    6778        this.Command.WindowRight = (int)this.numWindowRight.Value;
    6879        this.Command.Order = (int)this.numOrder.Value;
     80        this.Command.OrderOfDerivative = (int) this.numOrderOfDerivative.Value;
    6981      }
    70     }
    71 
    72     private void numOrder_ValueChanged(object sender, EventArgs e) {
    73       this.UpdateCommand();
    7482    }
    7583  }
Note: See TracChangeset for help on using the changeset viewer.