Lemma is an Electromagnetics API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WindowFilter.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* This file is part of Lemma, a geophysical modelling and inversion API */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /**
  6. @file
  7. @author Trevor Irons
  8. @date 07/20/2010
  9. @version $Id: windowfilter.h 193 2014-11-10 23:51:41Z tirons $
  10. **/
  11. #ifndef WINDOWFILTER_INC
  12. #define WINDOWFILTER_INC
  13. #include "Filter.h"
  14. namespace Lemma {
  15. // ===================================================================
  16. // Class: WindowFilter
  17. /**
  18. @class WindowFilter
  19. \ingroup LemmaCore
  20. \brief Fourier domain window filter.
  21. \details Current types are Hamming and Hanning. Others to be added.
  22. */
  23. // ===================================================================
  24. class WindowFilter : public Filter {
  25. friend std::ostream &operator<<(std::ostream &stream, const WindowFilter& ob);
  26. struct ctor_key {};
  27. public:
  28. // ==================== LIFECYCLE =======================
  29. /** Default constructor, inaccessible use NewSP */
  30. explicit WindowFilter ( const ctor_key& );
  31. /** DeSerializing constructor, usees factory DeSerialize method, inaccessible use DeSerialize*/
  32. WindowFilter ( const YAML::Node& node, const ctor_key& );
  33. /** Default constructor. */
  34. virtual ~WindowFilter ( );
  35. /**
  36. * Uses YAML to serialize this object.
  37. * @return a YAML::Node
  38. */
  39. YAML::Node Serialize() const;
  40. /**
  41. * Constructs an object from a YAML::Node.
  42. */
  43. static std::shared_ptr< WindowFilter > DeSerialize(const YAML::Node& node);
  44. /**
  45. * Factory method for generating concrete class.
  46. * @return a std::shared_ptr of type WindowFilter
  47. */
  48. static std::shared_ptr< WindowFilter > NewSP();
  49. // ==================== OPERATORS =======================
  50. // ==================== OPERATIONS =======================
  51. /// Sets the bandwith of the window.
  52. /// @param[in] width Bandwidth in Hz
  53. void SetBandwidth(const Real& width);
  54. /// Sets the sampling rate of an input time domain signal.
  55. /// @param[in] dt is the sampling rate, in seconds.
  56. void SetSamplingInterval(const Real& dt);
  57. /// Specifies the length of the time series to apply filter to.
  58. void SetNumberOfSamples(const int& nt);
  59. /// Sets the type of window to compute.
  60. void SetWindowType(const WINDOWTYPE& type);
  61. /** Returns the number of frequency bins for whole data record.
  62. * this is different then the length of the filter. This is
  63. * simply the length of the real to complex FFT, or
  64. * Nw = Nt%2 ? (Nt-1)/2+1 : (Nt)/2+1;
  65. * @return the number of frequency bins.
  66. */
  67. int GetNumberOfFrequencyBins();
  68. // ==================== ACCESS =======================
  69. // ==================== INQUIRY =======================
  70. /// Returns a Vector of the filter coefficients.
  71. VectorXr GetFilterCoefficients( );
  72. /** Returns the name of the underlying class, similiar to Python's type */
  73. virtual inline std::string GetName() const {
  74. return this->CName;
  75. }
  76. protected:
  77. // ==================== LIFECYCLE =======================
  78. private:
  79. // ==================== DATA MEMBERS =========================
  80. /// Width of the window
  81. int Width;
  82. /// Length of time series
  83. int Nt;
  84. /// Length of the frequency series representation
  85. int Nw;
  86. /// Sampling rate of a time domain signal
  87. Real SamplingRate;
  88. /// Bandwith of filter
  89. Real Bandwidth;
  90. /// The filter coefficients
  91. VectorXr Coefficients;
  92. /// The type of filter to use
  93. WINDOWTYPE Type;
  94. /** ASCII string representation of the class name */
  95. static constexpr auto CName = "WindowFilter";
  96. WindowFilter ( const WindowFilter& ) = delete;
  97. }; // ----- end of class WindowFilter -----
  98. } // ----- end of Lemma name -----
  99. #endif // ----- #ifndef WINDOWFILTER_INC -----