From 8d61ef77b2bbd0da8043aed557347183dd03a7dd Mon Sep 17 00:00:00 2001 From: Vanya Belyaev Date: Sun, 27 Oct 2024 14:58:34 +0100 Subject: [PATCH] Add Hilbert transform --- ReleaseNotes/release_notes.md | 3 +- source/include/Ostap/Hilbert.h | 108 +++++++++++++++++++++++++++++++++ source/src/Hilbert.cpp | 33 ++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 source/include/Ostap/Hilbert.h create mode 100644 source/src/Hilbert.cpp diff --git a/ReleaseNotes/release_notes.md b/ReleaseNotes/release_notes.md index 870c050a..177ebdac 100644 --- a/ReleaseNotes/release_notes.md +++ b/ReleaseNotes/release_notes.md @@ -7,7 +7,8 @@ 1. reduce code duplication between GoF-1D and Two-Sample Tests 1. Add Anderson-Darling and Cramer-von-Mises Two Sample Tests 1. Add progress bar to methdos dealing with unique/duplicated entries in dataset - + 1. Add Hilbert transform + ## Backward incompatible ## Bug fixes diff --git a/source/include/Ostap/Hilbert.h b/source/include/Ostap/Hilbert.h new file mode 100644 index 00000000..2a647142 --- /dev/null +++ b/source/include/Ostap/Hilbert.h @@ -0,0 +1,108 @@ +// ============================================================================ +#ifndef OSTAP_HILBERT_H +#define OSTAP_HILBERT_H 1 +// ============================================================================ +// Include files +// ============================================================================ +// STD&STL +// ============================================================================ +#include +// ============================================================================ +// Ostap +// ============================================================================ +#include "Ostap/Integrator.h" +// ============================================================================ +namespace Ostap +{ + // ========================================================================== + namespace Math + { + // ======================================================================== + /** @class Hilbert Ostap/Hilbert.h + * Simple class to implement Hilbert transform + * https://en.wikipedia.org/wiki/Hilbert_transform + */ + class Hilbert + { + // ====================================================================== + /** templated constructor from the function + * @param func the function + * @param tag unique tag/label for cache + * @param rescale rescale function for better numerical precison + * @param size size of integration workspace + */ + template + Hilbert + ( FUNCTION func , + const std::size_t tag = 0 , + const unsigned short rescale = 0 , + const double aprecision = 0 , + const double rprecision = 0 , + const double width = 0 , + const std::size_t size = 0 ) + : m_func ( func ) + , m_tag ( tag ) + , m_rescale ( rescale ) + , m_aprecision ( aprecision ) + , m_rprecision ( rprecision ) + , m_width ( width ) + , m_integrator ( size ) + {} ; + // ====================================================================== + public: + // ====================================================================== + /** templated creator from the function + * @param func the function + * @param tag unique tag/label for cache + * @param rescale rescale function for better numerical precison + * @param size size of integration workspace + */ + template + inline static Hilbert + create + ( FUNCTION func , + const std::size_t tag = 0 , + const unsigned short rescale = 0 , + const double aprecision = 0 , + const double rprecision = 0 , + const double width = 0 , + const std::size_t size = 0 ) + { return Hilbert ( func , tag , rescale , aprecision , rprecision , width , size ) ; } + // ====================================================================== + public: + // ====================================================================== + /// Get the value of Hilbert transform + double operator() ( const double x ) const ; + // ====================================================================== + public: + // ====================================================================== + /// get the value of the unction + inline double func ( const double x ) const { return m_func ( x ) ; } + // ====================================================================== + private: + // ====================================================================== + /// the function + std::function m_func ; // the function + /// unique tag/label + std::size_t m_tag ; // unique tag/label + /// rescale function for better numerical precision + unsigned short m_rescale ; // #rescale points + /// absolute precison + double m_aprecision ; // absolute preciison + /// relative precison + double m_rprecision ; // relative precision + /// width + double m_width ; // width + /// Integrator + Ostap::Math::Integrator m_integrator ; // integrator + // ====================================================================== + }; // The end of class Ostap::Math::Hilbert + // ======================================================================== + } // The end of namespace Ostap::Math + // ========================================================================== +} // The end of namepsace Ostap +// ============================================================================ +// The END +// ============================================================================ +#endif // OSTAP_HILBERT_H +// ============================================================================ diff --git a/source/src/Hilbert.cpp b/source/src/Hilbert.cpp new file mode 100644 index 00000000..4b7821d2 --- /dev/null +++ b/source/src/Hilbert.cpp @@ -0,0 +1,33 @@ +// ============================================================================ +// Include files +// ============================================================================= +// Incldue files +// ============================================================================= +// STD& STL +// ============================================================================= +#include +// ============================================================================= +// Ostap +// ============================================================================= +#include "Ostap/Hilbert.h" +// ============================================================================= +/** @file + * Implementation file for class Ostap::Math::Hilbert + * @date 2024-10-27 + * @author Vanya Belyaev Ivan.Belyaev@cern.ch + */ +// ============================================================================= +double Ostap::Math::Hilbert::operator() ( const double x ) const +{ return m_integrator.cauchy_pv_infinity + ( std::cref ( m_func ) , + x , + m_tag , + m_rescale , + m_aprecision , + m_rprecision , + m_width ) / M_PI ; } +// ============================================================================= +// The END +// ============================================================================= + +