diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bfff0b..57f2c22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,8 +63,6 @@ if(MSVC) set(CMAKE_MSVCIDE_RUN_PATH "\$(SolutionDir)/src/\$(Configuration)") endif() -add_compile_options("-D_USE_MATH_DEFINES") - # Eigen set(Eigen_REQUIRED "eigen3 >= 3.3") search_for_eigen() diff --git a/include/Butterworth.h b/include/Butterworth.h index e880817..e4c0a75 100644 --- a/include/Butterworth.h +++ b/include/Butterworth.h @@ -27,7 +27,6 @@ #include "DigitalFilter.h" #include "typedefs.h" -#include #include namespace difi { @@ -44,9 +43,6 @@ namespace difi { */ template class Butterworth : public DigitalFilter { -public: - static T PI; /*!< pi depending on the type T */ - public: /*! \brief Type of butterworth filter0 */ enum class Type { diff --git a/include/Butterworth.tpp b/include/Butterworth.tpp index 820c563..5eda8be 100644 --- a/include/Butterworth.tpp +++ b/include/Butterworth.tpp @@ -28,9 +28,6 @@ namespace difi { -template -T Butterworth::PI = static_cast(M_PI); - template std::pair Butterworth::findMinimumButter(T wPass, T wStop, T APass, T AStop) { @@ -38,8 +35,8 @@ std::pair Butterworth::findMinimumButter(T wPass, T wStop, T APass, T Expects(wStop > T(0) && wPass < T(1)); T num = std::log10((std::pow(T(10), T(0.1) * std::abs(AStop)) - 1) / (std::pow(T(10), T(0.1) * std::abs(APass)) - 1)); // pre-warp - T fwPass = std::tan(T(0.5) * PI * wPass); - T fwStop = std::tan(T(0.5) * PI * wStop); + T fwPass = std::tan(T(0.5) * pi * wPass); + T fwStop = std::tan(T(0.5) * pi * wStop); T w; if (wPass < wStop) w = std::abs(fwStop / fwPass); @@ -54,7 +51,7 @@ std::pair Butterworth::findMinimumButter(T wPass, T wStop, T APass, T else ctf = fwPass / ctf; - return std::pair(order, T(2) * std::atan(ctf) / PI); + return std::pair(order, T(2) * std::atan(ctf) / pi); } template @@ -111,7 +108,7 @@ template void Butterworth::computeDigitalRep(T fc) { // Continuous pre-warped frequency - T fpw = (m_fs / PI) * std::tan(PI * fc / m_fs); + T fpw = (m_fs / pi)*std::tan(pi * fc / m_fs); // Compute poles vectXc_t poles(m_order); @@ -138,8 +135,8 @@ void Butterworth::computeDigitalRep(T fc) template void Butterworth::computeBandDigitalRep(T fLower, T fUpper) { - T fpw1 = (m_fs / PI) * std::tan(PI * fLower / m_fs); - T fpw2 = (m_fs / PI) * std::tan(PI * fUpper / m_fs); + T fpw1 = (m_fs / pi)*std::tan(pi * fLower / m_fs); + T fpw2 = (m_fs / pi)*std::tan(pi * fUpper / m_fs); T fpw0 = std::sqrt(fpw1 * fpw2); vectXc_t poles(2 * m_order); @@ -161,7 +158,7 @@ void Butterworth::computeBandDigitalRep(T fLower, T fUpper) } if (m_type == Type::BandPass) - scaleAmplitude(aCoeff, bCoeff, std::exp(std::complex(T(0), T(2) * PI * std::sqrt(fLower * fUpper) / m_fs))); + scaleAmplitude(aCoeff, bCoeff, std::exp(std::complex(T(0), T(2) * pi * std::sqrt(fLower * fUpper) / m_fs))); else scaleAmplitude(aCoeff, bCoeff); @@ -171,16 +168,16 @@ void Butterworth::computeBandDigitalRep(T fLower, T fUpper) template std::complex Butterworth::generateAnalogPole(int k, T fpw1) { - auto thetaK = [pi = PI, order = m_order](int k) -> T { + auto thetaK = [pi = pi, order = m_order](int k) -> T { return (2 * k - 1) * pi / (2 * order); }; std::complex analogPole(-std::sin(thetaK(k)), std::cos(thetaK(k))); switch (m_type) { case Type::HighPass: - return T(2) * PI * fpw1 / analogPole; + return T(2) * pi * fpw1 / analogPole; case Type::LowPass: - return T(2) * PI * fpw1 * analogPole; + return T(2) * pi * fpw1 * analogPole; default: GSL_ASSUME(0); } @@ -189,13 +186,13 @@ std::complex Butterworth::generateAnalogPole(int k, T fpw1) template std::pair, std::complex> Butterworth::generateBandAnalogPole(int k, T fpw0, T bw) { - auto thetaK = [pi = PI, order = m_order](int k) -> T { + auto thetaK = [pi = pi, order = m_order](int k) -> T { return (2 * k - 1) * pi / (2 * order); }; std::complex analogPole(-std::sin(thetaK(k)), std::cos(thetaK(k))); std::pair, std::complex> poles; - std::complex s0 = T(2) * PI * fpw0; + std::complex s0 = T(2) * pi * fpw0; std::complex s = T(0.5) * bw / fpw0; switch (m_type) { case Type::BandReject: @@ -222,7 +219,7 @@ vectXc_t Butterworth::generateAnalogZeros(T fpw0) case Type::BandPass: return (vectXc_t(2 * m_order) << vectXc_t::Constant(m_order, std::complex(-1)), vectXc_t::Constant(m_order, std::complex(1))).finished(); case Type::BandReject: { - T w0 = T(2) * std::atan(PI * fpw0 / m_fs); + T w0 = T(2) * std::atan(pi * fpw0 / m_fs); return (vectXc_t(2 * m_order) << vectXc_t::Constant(m_order, std::exp(std::complex(0, w0))), vectXc_t::Constant(m_order, std::exp(std::complex(0, -w0)))).finished(); } case Type::LowPass: diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 86629ba..535cdae 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -24,7 +24,6 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set(HEADERS - gsl/gsl_assert.h BilinearTransform.h Butterworth.h Butterworth.tpp @@ -38,10 +37,13 @@ set(HEADERS typedefs.h ) +set(GSL_HEADERS gsl/gsl_assert.h) + add_library(${PROJECT_NAME} INTERFACE) -target_include_directories(${PROJECT_NAME} INTERFACE ${HEADERS}) +target_include_directories(${PROJECT_NAME} INTERFACE ${HEADERS} ${GSL_HEADERS}) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -install(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_DESTINATION}) \ No newline at end of file +install(FILES ${HEADERS} DESTINATION ${INCLUDE_INSTALL_DESTINATION}) +install(FILES ${GSL_HEADERS} DESTINATION ${INCLUDE_INSTALL_DESTINATION}/gsl) \ No newline at end of file diff --git a/include/GenericFilter.h b/include/GenericFilter.h index 84455bf..be23d71 100644 --- a/include/GenericFilter.h +++ b/include/GenericFilter.h @@ -25,6 +25,7 @@ #pragma once +#include "gsl/gsl_assert.h" #include "type_checks.h" #include "typedefs.h" #include diff --git a/include/MovingAverage.h b/include/MovingAverage.h index d1f29b1..6c84f2c 100644 --- a/include/MovingAverage.h +++ b/include/MovingAverage.h @@ -26,6 +26,7 @@ #pragma once #include "DigitalFilter.h" +#include "gsl/gsl_assert.h" #include "typedefs.h" namespace difi { diff --git a/include/typedefs.h b/include/typedefs.h index e855754..c6039b6 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -29,6 +29,9 @@ namespace difi { +template +constexpr T pi = T(3.14159265358979323846264338327950288419716939937510582097494459230781L); + template using vectX_t = Eigen::Matrix; /*!< Eigen column-vector */