|  | 
 
| python一维高斯滤波 B站:Halcom中国的动态-哔哩哔哩 (bilibili.com)
 
 
 复制代码        private static void SmoothFunct1dGauss(List<double> Function, double sigma, out List<double> SmoothedFunction)
        {
            SmoothedFunction = new List<double>();
            //  构造高斯核函数
            double mu = 0;       // 均值
            //double sigma = 5.3;  // sigma
            int LengthG = Convert.ToInt32(3 * sigma);
            if (LengthG < 1)
            {
                LengthG = 1;
            }
            List<double> GaussianKernel = new List<double>();
            for (int i = -LengthG; i <= LengthG; i++)
            {
                double xout = 0;
                GaussianCore(i, mu, sigma, out xout);
                GaussianKernel.Add(xout);
            }
            // 对一维数据序列进行卷积滤波
            //List<double> SmoothedFunction = new List<double>();
            for (int i = 0; i < Function.Count(); i++)
            {
                if (i <= 2)
                {
                    SmoothedFunction.Add(Function[i]);
                }
                else
                {
                    double xout = 0;
                    for (int j = 0; j < GaussianKernel.Count(); j++)
                    {
                        if (i + j - LengthG < 0)
                        {
                            xout = xout + GaussianKernel[j] * Function[i];
                        }
                        else if (i + j - LengthG > Function.Count() - 1)
                        {
                            xout = xout + GaussianKernel[j] * Function[i];
                        }
                        else
                        {
                            xout = xout + GaussianKernel[j] * Function[i + j - LengthG];
                        }
                    }
                    SmoothedFunction.Add(xout);
                }
            }
        }
 
 
 
 | 
 |