Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orginal">输入源信号</param>
        /// <param name="lev">分解层级</param>
        /// <param name="wname">haar、db1~db10</param>
        /// <returns>各层近似系数+细节系数,各层系数</returns>
        public static WaveDec1ViewModel WaveDec1(List <double> orginal, int lev = 1, string wname = "haar")
        {
            WaveDec1ViewModel result = new WaveDec1ViewModel();

            try
            {
                DWT           dwt = new DWT(orginal, wname);//获取到相关的分解系数
                List <double> co  = new List <double>();
                int[]         li  = new int[lev + 2];
                li[li.Length - 1] = orginal.Count;
                for (int i = 0; i < lev; i++)
                {
                    List <List <double> > data = DWTUtil.DWT1(orginal, dwt);
                    if (data != null && data.Count == 2)
                    {
                        orginal = data[0];
                        List <double> re = data[1];
                        if (re != null)
                        {
                            co          = re.Concat(co).ToList();
                            li[lev - i] = re.Count;
                        }
                    }
                }

                co    = orginal.Concat(co).ToList();
                li[0] = orginal.Count;
                result.AppAndDetail = co;
                result.Coefficient  = li.ToList();
                result.Dwt          = dwt;
            }
            catch (Exception ex)
            {
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orginal">输入源信号</param>
        /// <param name="lev">分解层级</param>
        /// <param name="wname">haar、db1~db10</param>
        /// <returns></returns>
        public static List <object> WaveDec2(List <List <double> > orginal, int lev = 1, string wname = "haar")
        {
            List <object> result = new List <object>();

            try
            {
                if (orginal != null && orginal.Any())
                {
                    DWT dwt = new DWT(orginal, wname);//获取到相关的分解系数
                    if (dwt != null && dwt.Lo_D != null && dwt.Hi_D != null && dwt.Lo_D.Count == dwt.Hi_D.Count)
                    {
                        List <double>         cl = new List <double>();
                        List <List <double> > s = new List <List <double> >();
                        int r = lev + 2, c = orginal.Count;
                        for (int i = 0; i < r - 1; i++)
                        {
                            List <double> item = new List <double>();
                            for (int j = 0; j < 2; j++)
                            {
                                item.Add(0);
                            }
                            s.Add(item);
                        }
                        s.Add(new List <double> {
                            c, orginal[0].Count
                        });

                        for (int i = 1; i <= lev; i++)
                        {
                            Dictionary <int, List <List <double> > > data = DWTUtil.DWT2(orginal, dwt);
                            if (data != null && data.Count == 4)
                            {
                                //近似分量
                                orginal = data[0];
                                //水平细节分量
                                List <List <double> > ch = data[1];
                                //垂直细节分量
                                List <List <double> > cv = data[2];
                                //对角细节分量
                                List <List <double> > cd = data[3];

                                //可优化,没有操作ca,看DWT2是否需要进行ca的值获取
                                cl = ConvertToLA(ch).Concat(ConvertToLA(cv)).Concat(ConvertToLA(cd)).Concat(cl).ToList();

                                s[r - i - 1] = new List <double> {
                                    orginal.Count, orginal[0].Count
                                };
                            }
                        }
                        s[0] = new List <double> {
                            orginal.Count, orginal[0].Count
                        };

                        result.Add(ConvertToLA(orginal).Concat(cl).ToList());
                        result.Add(s);
                    }
                }
            }
            catch (Exception ex)
            {
                var sd = ex;
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 小波基函数
        /// </summary>
        /// <param name="wname">小波名称</param>
        /// <param name="infoModel">小波信息</param>
        /// <param name="iter">迭代次数</param>
        public static WavefunModel Wavefun(string wname, WaveletsInfoModel infoModel, int iter)
        {
            WavefunModel data = new WavefunModel();

            if (!string.IsNullOrEmpty(wname))
            {
                string debut = wname.Substring(0, 2);
                double coef = Math.Pow(Math.Sqrt(2), iter), pas = (double)1 / Math.Pow(2, iter);
                switch (infoModel.type)
                {
                case 1:
                    DWT dwt   = new DWT(wname);
                    int logn  = dwt.Lo_R.Count;
                    int nbpts = Convert.ToInt32((logn - 1) / pas + 1);

                    List <double> psi = DWTUtil.Upcoef("d", dwt, iter);
                    if (psi != null && psi.Any())
                    {
                        psi = psi.Select(m => m * coef).ToList();
                    }
                    List <int> result = GetNBpts(nbpts, iter, logn);   //nbpts、nb、dn

                    int nb = result[1], dn = result[2] + 1;
                    nbpts = result[0];
                    DWTUtil.Wkeep1(psi, nb, "c");
                    psi.Insert(0, 0);
                    for (int i = 1; i <= dn; i++)
                    {
                        psi.Add(0);
                    }

                    //sign depends on wavelet
                    if ("co".Equals(debut) || "sy".Equals(debut) || "dm".Equals(debut))
                    {
                        psi = psi.Select(m => - m).ToList();
                    }

                    //data.phi = phi;
                    data.psi  = psi;
                    data.type = infoModel.type;
                    data.xval = Linspace(0, (nbpts - 1) * pas, nbpts);
                    break;

                case 2:
                    break;

                case 3:
                    break;

                case 4:
                    data = Morlet(infoModel.bounds[0], infoModel.bounds[1], (int)Math.Pow(2, iter));
                    break;

                case 5:
                    break;

                default:
                    break;
                }
            }
            return(data);
        }