#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 // https://www.dsprelated.com/showarticle/1131.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 fLower, T fUpper, T fs, Type type = Type::BandPass); void setFilterParameters(int order, T fc, T fs); void setFilterParameters(int order, T f0, T fLimit, T fs); private: void initialize(int order, T f0, T fLimit, T fs); // f0 = fc for LowPass/HighPass filter void computeDigitalRep(T fc); void computeBandDigitalRep(T fLower, T fUpper); std::complex generateAnalogPole(int k, T fpw); std::pair, std::complex> generateBandAnalogPole(int k, T fpw0, T bw); vectXc_t generateAnalogZeros(T f0 = T()); void scaleAmplitude(const vectX_t& aCoeff, Eigen::Ref> bCoeff, const std::complex& bpS = T()); private: Type m_type; int m_order; T m_fs; vectXc_t m_poles; }; } // namespace fratio #include "Butterworth.tpp"