Example #1
0
        private bool DesignBilinear(double fc, double fs, long sampleFreq, AnalogFilterDesign.FilterType filterType)
        {
            double twoπ = 2.0 * Math.PI;

            mIIRBilinear = new BilinearDesign(fc, sampleFreq);

            double fc_pw = mIIRBilinear.PrewarpωtoΩ(twoπ * fc) / twoπ;
            double fs_pw = mIIRBilinear.PrewarpωtoΩ(twoπ * fs) / twoπ;

            mAfd = new AnalogFilterDesign();
            mAfd.DesignLowpass(0, CUTOFF_GAIN_DB, StopbandRippleDb(),
                               fc_pw, fs_pw,
                               filterType,
                               ApproximationBase.BetaType.BetaMax);

            // 連続時間伝達関数を離散時間伝達関数に変換。
            for (int i = 0; i < mAfd.HPfdCount(); ++i)
            {
                var s = mAfd.HPfdNth(i);
                mIIRBilinear.Add(s);
            }
            mIIRBilinear.Calc();

            return(true);
        }
Example #2
0
        private bool DesignImpulseInvariance(double fc, double fs, long samplingFreq, AnalogFilterDesign.FilterType filterType)
        {
            mAfd = new AnalogFilterDesign();
            mAfd.DesignLowpass(0, CUTOFF_GAIN_DB, StopbandRippleDb(),
                               fc,
                               fs,
                               filterType,
                               ApproximationBase.BetaType.BetaMax);

            var H_s = new List <FirstOrderComplexRationalPolynomial>();

            for (int i = 0; i < mAfd.HPfdCount(); ++i)
            {
                var p = mAfd.HPfdNth(i);
                H_s.Add(p);
            }

            mIIRiim = new ImpulseInvarianceMethod(H_s, fc * 2.0 * Math.PI, samplingFreq, mMethod == Method.ImpulseInvarianceMinimumPhase);
            return(true);
        }
Example #3
0
        void CalcFilter(object sender, DoWorkEventArgs e)
        {
            var r = new BackgroundCalcResult();

            e.Result = r;

            r.success = false;
            r.message = "unknown error";

            mAfd = new AnalogFilterDesign();
            try {
                mAfd.DesignLowpass(mG0, mGc, mGs, mFc, mFs, mFilterType, mBetaType);
                r.success = true;
            } catch (System.ArgumentOutOfRangeException ex) {
                r.message = string.Format("Design failed! {0}", ex);
                return;
            } catch (System.Exception ex) {
                r.message = string.Format("BUG: should be fixed! {0}", ex);
                return;
            }
        }