Esempio n. 1
0
        static FirFilterKernelDescription CreateGaussianFilterKernel(double cutoffFrequency, double samplingPeriod, FilterType filterType)
        {
            double alpha = Math.Sqrt(Math.Log(2.0) / Math.PI);

            int windowLength = (int)Math.Ceiling(1.0 / (cutoffFrequency * samplingPeriod));

            FirFilterKernelDescription ret = new FirFilterKernelDescription();

            ret.Kernel = new double[2 * windowLength + 1];

            double normalizationConstant = 0;
            double evalConst             = -Math.PI * Math.Pow(samplingPeriod * cutoffFrequency / alpha, 2);

            for (int i = -windowLength; i <= windowLength; i++)
            {
                normalizationConstant += Math.Exp(evalConst * i * i);
            }

            normalizationConstant = 1.0 / normalizationConstant;

            ret.Offset = windowLength;

            //we use spectral inversion to create a high-pass filter
            double sign = (filterType == FilterType.LowPass) ? 1 : -1;

            for (int i = 0; i <= windowLength; i++)
            {
                double value = sign * normalizationConstant * Math.Exp(evalConst * i * i);
                ret.Kernel[i + ret.Offset] = value;
                ret.Kernel[ret.Offset - i] = value;
            }

            if (filterType == FilterType.HighPass)
            {
                ret.Kernel[ret.Offset] += 1;
            }

            return(ret);
        }
Esempio n. 2
0
 FirFilter(FirFilterKernelDescription descr)
 {
     m_kernelSize        = descr.Kernel.Length;
     m_kernelDescription = descr;
 }