Exemple #1
0
        public static float[] filterFFT(float[] res, double filter)
        {
            int          reslen = res.Length;
            List <float> Y      = new List <float>(res);

            Console.WriteLine("ydata:" + res.Length);
            Console.WriteLine("a:" + Y.ToArray().Length);
            Y = TWFFT.DataFill(Y);
            Console.WriteLine("b:" + Y.ToArray().Length);
            float[] y = new float[Y.ToArray().Length];
            y = TWFFT.FFT_filter(Y.ToArray(), filter); //第二个参数可调,调整范围是:(0,1)。为1 的时候没有滤波效果,为0的时候将所有频率都过滤掉。
            int putlen = TWFFT.putlen;                 //获取填充数据的长度的一半

            Console.WriteLine("putlen:" + putlen);
            Console.WriteLine("a:" + Y.ToArray().Length);
            for (int i = 0; i < reslen; i++)
            {
                res[i] = (float)Math.Round(y[i + putlen], 2);
            }
            return(res);
        }
Exemple #2
0
        public static float[] FFT_filter(double[] res, double filter)
        {
            //a是实部、b是虚部

            float[]      a   = new float[res.Length];
            float[]      b   = new float[res.Length];
            List <float> ans = new List <float>();

            for (int j = 0; j < res.Length; j++)
            {
                //  Console.WriteLine("I:" + j);
                a[j] = (float)res[j];
                b[j] = 0.0f;
            }
            length = TWFFT.FFT(a, b);
            //length是傅里叶变换处理过后的数组大小
            //在频域上对数据进行过滤
            int p = (int)(length * filter);

            for (int i = 0; i < length; i++)
            {
                if (p < i && i < length - p)
                {
                    a[i] = 0f;
                    b[i] = 0f;
                }
            }
            length = TWFFT.IFFT(a, b);
            for (int i = 0; i < length; i++)
            {
                //Console.WriteLine("{0}\t{1}\t{2}", i, a[i], b[i]);
                ans.Add((float)Math.Sqrt(a[i] * a[i] + b[i] * b[i]));
            }

            return(ans.ToArray());
        }