示例#1
0
        private FilterInfo CreateFilter(int lowFrequency, int highFrequency, int filterOrder)
        {
            double[]        coefficients = FirCoefficients.BandPass(SamplingRate, lowFrequency, highFrequency, filterOrder);
            OnlineFirFilter filter       = new OnlineFirFilter(coefficients);

            return(new FilterInfo(filter, lowFrequency, highFrequency));
        }
示例#2
0
        /// <summary>
        /// Create a filter to remove middle (all but low and high) frequencies in online processing scenarios.
        /// </summary>
        public static OnlineFilter CreateBandstop(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order)
        {
            if (mode == ImpulseResponse.Finite)
            {
                double[] c = FirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1);
                return(new OnlineFirFilter(c));
            }

            if (mode == ImpulseResponse.Infinite)
            {
                double[] c = IirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate);
                return(new OnlineIirFilter(c));
            }

            throw new ArgumentException("mode");
        }
示例#3
0
        /// <summary>
        /// Create a filter to remove low frequencies in online processing scenarios.
        /// </summary>
        public static OnlineFilter CreateHighpass(ImpulseResponse mode, double sampleRate, double cutoffRate, int order)
        {
            if (mode == ImpulseResponse.Finite)
            {
                double[] c = FirCoefficients.HighPass(sampleRate, cutoffRate, order >> 1);
                return(new OnlineFirFilter(c));
            }

            if (mode == ImpulseResponse.Infinite)
            {
                // TODO: investigate (bandwidth)
                double[] c = IirCoefficients.HighPass(sampleRate, cutoffRate, cutoffRate);
                return(new OnlineIirFilter(c));
            }

            throw new ArgumentException("mode");
        }
示例#4
0
    /**
     * 零相位延迟FIR滤波
     * @param:
     *      dataSerial          输入波形
     *      samplingFreq        采样率 Hz
     *      lowCutOff           低截至频率 Hz
     *      highCutOff          高截至频率 Hz
     *
     * @return FIRResult        滤波后数据
     */
    public double[] ZeroPhaseFIR(double[] dataSerial, double samplingFreq, double lowCutOff, double highCutOff)
    {
        IList <double> coef = new List <double>();

        double[] hf = FirCoefficients.BandPass(samplingFreq, lowCutOff, highCutOff, 64);     //获得滤波系数
        foreach (double number in hf)
        {
            coef.Add(number);
        }

        OnlineFirFilter filter = new OnlineFirFilter(coef);

        double[] FIRResult = filter.ProcessSamples(dataSerial);           //正向滤波
        FIRResult = filter.ProcessSamples(FIRResult.Reverse().ToArray()); //反向滤波
        FIRResult = FIRResult.Reverse().ToArray();                        //反转

        return(FIRResult);
    }
示例#5
0
        public OnlineFirFilter SetFilter(CtkPassFilterStruct pfarg)
        {
            var flag = this.filter != null;

            flag &= this.FilterArgs.Mode == pfarg.Mode;
            flag &= this.FilterArgs.SampleRate == pfarg.SampleRate;
            flag &= this.FilterArgs.CutoffLow == pfarg.CutoffLow;
            flag &= this.FilterArgs.CutoffHigh == pfarg.CutoffHigh;

            if (flag)
            {
                return(filter);
            }

            this.FilterArgs = pfarg;


            var coff = new double[0];

            switch (this.FilterArgs.Mode)
            {
            case CtkEnumPassFilterMode.BandPass:
                coff = FirCoefficients.BandPass(this.FilterArgs.SampleRate, this.FilterArgs.CutoffLow, this.FilterArgs.CutoffHigh);
                break;

            case CtkEnumPassFilterMode.LowPass:
                coff = FirCoefficients.LowPass(this.FilterArgs.SampleRate, this.FilterArgs.CutoffLow);
                break;

            case CtkEnumPassFilterMode.HighPass:
                coff = FirCoefficients.HighPass(this.FilterArgs.SampleRate, this.FilterArgs.CutoffHigh);
                break;

            default:
                throw new NotImplementedException();
            }

            filter = new OnlineFirFilter(coff);
            return(filter);
        }
示例#6
0
        private void RefreshCoefficient()
        {
            double[]            coefficient = null;
            SoftPanelGlobalInfo globalInfo  = SoftPanelGlobalInfo.GetInstance();
            FilterType          type        = (FilterType)Enum.Parse(typeof(FilterType), metroComboBox_type.Text);
            double lowCutoff  = double.Parse(textBox_lowerCutoff.Text);
            double highCutoff = double.Parse(textBox_highCutoff.Text);

            switch (type)
            {
            case FilterType.LowPass:
                coefficient = FirCoefficients.LowPass(globalInfo.SampleRate, lowCutoff);
                break;

            case FilterType.HighPass:
                coefficient = FirCoefficients.HighPass(globalInfo.SampleRate, highCutoff);
                break;

            case FilterType.BandPass:
                if (lowCutoff > highCutoff)
                {
                    double tmp = lowCutoff;
                    lowCutoff  = highCutoff;
                    highCutoff = tmp;
                }
                coefficient = FirCoefficients.BandPass(globalInfo.SampleRate, lowCutoff, highCutoff);
                break;

            case FilterType.BandStop:
                if (lowCutoff > highCutoff)
                {
                    double tmp = lowCutoff;
                    lowCutoff  = highCutoff;
                    highCutoff = tmp;
                }
                coefficient = FirCoefficients.BandStop(globalInfo.SampleRate, lowCutoff, highCutoff);
                break;
            }
            _filter = new OnlineFirFilter(coefficient);
        }