wavelet_transforms.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright Nick Thompson, 2020
  3. * Use, modification and distribution are subject to the
  4. * Boost Software License, Version 1.0. (See accompanying file
  5. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #ifndef BOOST_MATH_QUADRATURE_WAVELET_TRANSFORMS_HPP
  8. #define BOOST_MATH_QUADRATURE_WAVELET_TRANSFORMS_HPP
  9. #include <boost/math/special_functions/daubechies_wavelet.hpp>
  10. #include <boost/math/quadrature/trapezoidal.hpp>
  11. namespace boost::math::quadrature {
  12. template<class F, typename Real, int p>
  13. class daubechies_wavelet_transform
  14. {
  15. public:
  16. daubechies_wavelet_transform(F f, int grid_refinements = -1, Real tol = 100*std::numeric_limits<Real>::epsilon(),
  17. int max_refinements = 12) : f_{f}, psi_(grid_refinements), tol_{tol}, max_refinements_{max_refinements}
  18. {}
  19. daubechies_wavelet_transform(F f, boost::math::daubechies_wavelet<Real, p> wavelet, Real tol = 100*std::numeric_limits<Real>::epsilon(),
  20. int max_refinements = 12) : f_{f}, psi_{wavelet}, tol_{tol}, max_refinements_{max_refinements}
  21. {}
  22. auto operator()(Real s, Real t)->decltype(std::declval<F>()(std::declval<Real>())) const
  23. {
  24. using std::sqrt;
  25. using std::abs;
  26. using boost::math::quadrature::trapezoidal;
  27. auto g = [&] (Real u) {
  28. return f_(s*u+t)*psi_(u);
  29. };
  30. auto [a,b] = psi_.support();
  31. return sqrt(abs(s))*trapezoidal(g, a, b, tol_, max_refinements_);
  32. }
  33. private:
  34. F f_;
  35. boost::math::daubechies_wavelet<Real, p> psi_;
  36. Real tol_;
  37. int max_refinements_;
  38. };
  39. }
  40. #endif