#pragma once #include "DigitalFilter.h" #include "typedefs.h" #include #include namespace fratio { // https://www.dsprelated.com/showarticle/1119.php // https://www.dsprelated.com/showarticle/1135.php // https://www.dsprelated.com/showarticle/1128.php template class Butterworth : public DigitalFilter { public: T PI = static_cast(M_PI); public: enum class Type { LowPass, HighPass, BandPass, BandReject }; // public: // static double minimumRequiredFrequency(...); public: Butterworth(Type type = Type::LowPass); Butterworth(int order, T fc, T fs, Type type = Type::LowPass); Butterworth(int order, T bw, T fs, T fCenter, Type type = Type::BandPass); void setFilterParameters(int order, T fc, T fs, T fCenter = T(0)); private: void initialize(int order, T fc, T fs, T fCenter = T(0)); // fc = bw for bandPass filter void computeDigitalRep(T fc); void computeBandDigitalRep(T bw, T fCenter); std::complex generateAnalogPole(int k, T fpw); std::pair, std::complex> generateBandAnalogPole(int k, T fpw1, T fpw2); vectXc_t generateAnalogZeros(); void scaleAmplitude(Eigen::Ref> aCoeff, Eigen::Ref> bCoeff); private: Type m_type; int m_order; T m_fc; T m_bw; T m_fs; T m_fCenter; vectXc_t m_poles; }; } // namespace fratio #include "Butterworth.tpp"