等差滤波器代码设计C#

写个等差滤波器,思想时处理高斯随机误差,使数据平滑些而又合理性。不够高大上,但是写在这里,提高大家工作效率。天下代码一大抄,思想传播。。。下面用的使C#,简单明白,公式原理不在说明。喜欢抄走。

 class currentDPointLocClass
    {
        private float currentpointX;
        private float currentpointY;
        private float currentpointZ;
        private int enNumber;
        private float diffx;
        private float diffy;
        private List<locationClassconfig> currentPtList;

        public currentDPointLocClass()
        {
            currentpointX = 0;
            currentpointY = 0;
            currentpointZ = 0;
            enNumber = 8;
            diffx =8.4f;
            diffy = 8.4f;
            currentPtList = new List<locationClassconfig>();

        }




        public void addPtPool(float pdx, float pdy ,float pdz)
        {
            if (Math.Abs(pdx - currentpointX) > diffx || Math.Abs(pdy - currentpointY) > diffy)
            {
                currentPtList.Clear();
                currentpointX = pdx;
                currentpointY = pdy;
                currentpointZ = pdz;

            }
            else {

                if (currentPtList.Count > enNumber)
                {
                    currentPtList.RemoveRange(0,2);

                }
                locationClassconfig mlocpt = new locationClassconfig(pdx, pdy, pdz);
                currentPtList.Add(mlocpt);


                int listsize = currentPtList.Count;


                if (listsize > 3)
                {

                    float tmpsize = listsize;
                    float tmpdf = 1.0f / (tmpsize * 2.0f);

                    float tmpdc = (2.0f * tmpsize - 1) / (tmpsize * tmpsize - tmpsize);

                    float sumx = 0;
                    float sumy = 0;
                    float sumz = 0;

                    for (int i = 0; i < listsize; i++)
                    {
                        sumx += currentPtList[i].get_locX() * (tmpdf + tmpdc * i) / tmpsize;
                        sumy += currentPtList[i].get_locY() * (tmpdf + tmpdc * i) / tmpsize;
                        sumz += currentPtList[i].get_locZ() * (tmpdf + tmpdc * i) / tmpsize;
                    }
                    currentpointX = sumx;
                    currentpointY = sumy;
                    currentpointZ = sumz;

                }
                else
                {
                    float sumx = 0;
                    float sumy = 0;
                    float sumz = 0;

                    for (int i = 0; i < listsize; i++)
                    {
                        sumx += currentPtList[i].get_locX();
                        sumy += currentPtList[i].get_locY();
                        sumz += currentPtList[i].get_locZ();
                    }
                    currentpointX = sumx / listsize;
                    currentpointY = sumy / listsize;
                    currentpointZ = sumz / listsize;

                }




            }

        }

        public float get_currentpointX()
        {
            return currentpointX;
        }

        public float get_currentpointY()
        {
            return currentpointY;
        }
        public float get_currentpointZ()
        {
            return currentpointZ;
        }

        public  void set_sumNumber(int num)
        {


            if (num < 3)
            {
                enNumber = 3;
            }
            else {
                enNumber = num;

            }


        }

        public void set_diffxy(float dfxy)
        {
            diffx = dfxy;
            diffy = dfxy;
        }
        public void set_diffx(float dfx)
        {
            diffx = dfx;
        }
        public void set_diffy(float dfy)
        {
            diffy = dfy;
        }

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值