过滤应用多次

时间:2018-04-09 07:31:17

标签: c# filtering butterworth

我正在使用描述here的第四阶巴特沃斯滤波器。我创建了一个按钮来过滤我的数据并在Click事件上绘制它们。除了一件事之外,它的工作原理非常好:如果我在按钮上多次单击,数据会被进一步过滤,每次给我一条“更平滑”的曲线。我不确定这是否是我想要摆脱的东西,但我想首先理解这种行为,因为我感觉输入数据没有被修改,所以这不应该发生。

这是我的按钮代码:

/// <summary>
    /// Handles the Click event on the smoothExperimentDataButton button ; applies 4th order Butterworth filter to the Experiment data and plots it
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="f"></param>
    private void smoothExperimentDataButton_Click(object sender, EventArgs f)
    {
        chart1.Series["Filtered experiment"].Points.Clear();
        double Samplingrate = 1 / deltaTimeinsec;
        long dF2 = ValeurPixelsSumExperiment.Length - 1;
        double[] Dat2 = new double[dF2 + 4];
        double[] data = ValeurPixelsSumExperiment;

        // Copy input data to Dat2
        for (long r = 0; r < dF2; r++)
        {
            Dat2[2 + r] = ValeurPixelsSumExperiment[r];
        }
        Dat2[1] = Dat2[0] = ValeurPixelsSumExperiment[0];
        Dat2[dF2 + 3] = Dat2[dF2 + 2] = ValeurPixelsSumExperiment[dF2];

        const double pi = 3.14159265358979;
        double wc = Math.Tan(CutOff * pi / Samplingrate);
        double k1 = 1.414213562 * wc; // Sqrt(2) * wc
        double k2 = wc * wc;
        double a = k2 / (1 + k1 + k2);
        double b = 2 * a;
        double c = a;
        double k3 = b / k2;
        double d = -2 * a + k3;
        double e = 1 - (2 * a) - k3;

        // RECURSIVE TRIGGERS - ENABLE filter is performed (first, last points constant)
        double[] DatYt = new double[dF2 + 4];
        DatYt[1] = DatYt[0] = ValeurPixelsSumExperiment[0];
        for (long s = 2; s < dF2 + 2; s++)
        {
            DatYt[s] = a * Dat2[s] + b * Dat2[s - 1] + c * Dat2[s - 2] + d * DatYt[s - 1] + e * DatYt[s - 2];
        }
        DatYt[dF2 + 3] = DatYt[dF2 + 2] = DatYt[dF2 + 1];

        // FORWARD filter
        double[] DatZt = new double[dF2 + 2];
        DatZt[dF2] = DatYt[dF2 + 2];
        DatZt[dF2 + 1] = DatYt[dF2 + 3];
        for (long t = -dF2 + 1; t <= 0; t++)
        {
            DatZt[-t] = a * DatYt[-t + 2] + b * DatYt[-t + 3] + c * DatYt[-t + 4] + d * DatZt[-t + 1] + e * DatZt[-t + 2];
        }

        // Calculated points copied for return
        for (long p = 0; p < dF2; p++)
        {
            data[p] = DatZt[p];
        }

        for (int i = 1; i < 1023; i++)
        {
            chart1.Series["Filtered experiment"].Points.AddXY(i, data[i]);
        }
        chart1.Series["Experiment"].Points.Clear();
    }

非常感谢!

1 个答案:

答案 0 :(得分:0)

在这一行:

double[] data = ValeurPixelsSumExperiment;

data将引用ValeurPixelsSumExperiment数组,该数组似乎包含您的源数据。

所以无论你在哪里data[x] = y;,你基本上都在做ValeurPixelsSumExperiment[x] = y;(覆盖输入数据)

计算结束时会发生什么:

// Calculated points copied for return
for (long p = 0; p < dF2; p++)
{
    data[p] = DatZt[p];
}