Пример #1
0
        /// <summary>
        /// 积分小波函数
        /// </summary>
        /// <param name="type"></param>
        /// <param name="wname"></param>
        /// <param name="precis"></param>
        public static WavefunModel Intwave(WaveletsInfoModel infoModel, string wname, int precis)
        {
            WavefunModel wf = null;

            try
            {
                wf = WavemngrUtil.Wavefun(wname, infoModel, precis);
                if (wf != null)
                {
                    int           type = infoModel.type;
                    List <double> xval = wf.xval, psi = wf.psi;
                    if (xval != null && xval.Count > 1)
                    {
                        double step = wf.step = xval[1] - xval[0], temp = 0;
                        if (type == 1 || type == 3 || type == 4 || type == 5)
                        {
                            List <double> out1 = new List <double>();
                            for (int i = 0; i < psi.Count; i++)
                            {
                                temp += psi[i];
                                out1.Add(temp * step);
                            }

                            wf.out1 = out1;
                            return(wf);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var sd = ex;
            }
            return(null);
        }
Пример #2
0
        /// <summary>
        /// 计算以wname命名的母小波的中心频率
        /// </summary>
        /// <param name="wname">小波名称</param>
        /// <param name="iter">迭代次数</param>
        /// <returns></returns>
        public static WaveletsInfoModel CentFrq(string wname, int iter = 8)
        {
            WaveletsInfoModel infoModel = WavemngrUtil.Command("type", wname);

            if (infoModel != null)
            {
                try
                {
                    WavefunModel wf = WavemngrUtil.Wavefun(wname, infoModel, iter);
                    if (wf != null)
                    {
                        List <double> xval = wf.xval, psi = wf.psi;
                        double        T = xval.Max() - xval.Min(), meanpsi = psi.Average();
                        int           n    = psi.Count;
                        var           sdsd = psi.Max();
                        psi = psi.Select(m => m - meanpsi).ToList();

                        ///-----------------------------要修改
                        Complex[] sdsw  = new Complex[n];
                        Complex[] sdswo = new Complex[n];
                        for (int j = 0; j < n; j++)
                        {
                            sdsw[j] = new Complex(psi[j], 0);
                        }
                        var input  = new PinnedArray <Complex>(sdsw);
                        var output = new PinnedArray <Complex>(sdswo);

                        List <double> sp = new List <double>();
                        DFT.FFT(input, output);

                        int len = output.Buffer.Length;
                        for (int i = 0; i < len; i++)
                        {
                            Complex val = (Complex)output.Buffer.GetValue(i);
                            sp.Add(Math.Sqrt(val.Real * val.Real + val.Imaginary * val.Imaginary));
                        }

                        double vmax   = sp.Max();         //最大值
                        int    indmax = sp.IndexOf(vmax); //下标
                        if (indmax > (double)n / 2)
                        {
                            indmax = n - indmax;
                        }

                        infoModel.centerfc = (double)indmax / T;
                    }
                }
                catch (Exception ex)
                {
                }
                //switch (wtype)
                //{
                //    case 1:
                //        break;
                //    case 2:
                //        break;
                //    case 3:
                //        break;
                //    case 4:
                //        break;
                //    case 5:
                //        break;
                //    default:
                //        break;
                //}
            }
            return(infoModel);
        }