Skip to content

Commit

Permalink
Add Hilbert transform
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Oct 27, 2024
1 parent 584534d commit 8d61ef7
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
108 changes: 108 additions & 0 deletions source/include/Ostap/Hilbert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// ============================================================================
#ifndef OSTAP_HILBERT_H
#define OSTAP_HILBERT_H 1
// ============================================================================
// Include files
// ============================================================================
// STD&STL
// ============================================================================
#include <functional>
// ============================================================================
// 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 <class FUNCTION>
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 <class FUNCTION>
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<double(double)> 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
// ============================================================================
33 changes: 33 additions & 0 deletions source/src/Hilbert.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ============================================================================
// Include files
// =============================================================================
// Incldue files
// =============================================================================
// STD& STL
// =============================================================================
#include <cmath>
// =============================================================================
// Ostap
// =============================================================================
#include "Ostap/Hilbert.h"
// =============================================================================
/** @file
* Implementation file for class Ostap::Math::Hilbert
* @date 2024-10-27
* @author Vanya Belyaev [email protected]
*/
// =============================================================================
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
// =============================================================================


0 comments on commit 8d61ef7

Please sign in to comment.