Ejemplo n.º 1
0
        /// <summary>
        /// 通过波形数据(List)得到频域Y轴数据
        /// </summary>
        /// <param name="wave"></param>
        /// <param name="fs"></param>
        /// <param name="isEnvl"></param>
        /// <returns></returns>
        public static List <double> GetFDYData(List <float> wave, float fs, bool isEnvl)
        {
            try
            {
                if (wave == null || wave.Count == 0)
                {
                    return(null);
                }

                float[]  waveF = wave.ToArray();
                double[] das   = new double[waveF.Length];
                for (int i = 0; i < das.Length; i++)
                {
                    das[i] = (double)waveF[i];
                }

                if (isEnvl == true)
                {
                    //包络频谱均值拉平
                    double dc = das.Average();

                    for (int inx = 0; inx < das.Length; inx++)
                    {
                        das[inx] = das[inx] - dc;
                    }
                }
                return(FrepTools.GetFrepData(das, (double)fs).ToList());
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 创建人:张辽阔
        /// 创建时间:2016-08-02
        /// 创建记录:得到频域Y轴数据
        /// </summary>
        /// <param name="path">Y轴数据存储路径</param>
        /// <param name="fs">采样频率</param>
        /// <param name="isEnvl">是否包络</param>
        /// <returns></returns>
        public static List <double> GetFDYData(string path, float fs, bool isEnvl)
        {
            try
            {
                lock (LockFile)
                {
                    FileStream   aFile    = new FileStream(path, FileMode.Open);
                    StreamReader sr       = new StreamReader(aFile);
                    string       datas    = sr.ReadToEnd();
                    string[]     datasStr = datas.Split(',');
                    aFile.Dispose();
                    sr.Dispose();
                    double[] das = Array.ConvertAll <string, double>(datasStr, item => double.Parse(item));

                    //包络频谱做均值拉平处理
                    if (isEnvl == true)
                    {
                        double dc = das.Average();

                        for (int inx = 0; inx < das.Length; inx++)
                        {
                            das[inx] = das[inx] - dc;
                        }
                    }

                    return(FrepTools.GetFrepData(das, (double)fs).ToList());
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
                return(null);
            }
        }