ComplexLgAmpPhase.h
Go to the documentation of this file.
1 #ifndef _utl_ComplexLgAmpPhase_h_
2 #define _utl_ComplexLgAmpPhase_h_
3 
4 #include <cmath>
5 #include <complex>
6 #include <iostream>
7 #include <utl/AugerException.h>
8 
20 namespace utl {
21 
32 
33  public:
36 
38  ComplexLgAmpPhase(const double lgamp, const double phase = 0)
39  : fLgAmplitude(lgamp), fPhase(phase) { }
40 
42  double GetLgAmplitude() const
43  { return fLgAmplitude; }
44 
46  double GetAmplitude() const
47  { return std::pow(10.0,fLgAmplitude); }
48 
50  double GetPhase() const
51  { return fPhase; }
52 
54  std::complex<double> GetComplex() const
55  { return std::pow(10.0,fLgAmplitude) * std::exp(std::complex<double>(0, 1) * fPhase); }
56 
58  double GetReal() const
59  { return GetComplex().real(); }
60 
62  double GetImag() const
63  { return GetComplex().imag(); }
64 
65  // careful, it is not possible to implement addition or subtraction without losing the extra phase information!
66 
68  operator*(const ComplexLgAmpPhase& rhs) const
69  {
70  double newLgAmplitude = this->fLgAmplitude + rhs.fLgAmplitude;
71  double newPhase = this->fPhase + rhs.fPhase;
72  return ComplexLgAmpPhase(newLgAmplitude,newPhase);
73  }
74 
76  operator/(const ComplexLgAmpPhase& rhs) const
77  {
78  double newLgAmplitude = this->fLgAmplitude - rhs.fLgAmplitude;
79  double newPhase = this->fPhase - rhs.fPhase;
80  return ComplexLgAmpPhase(newLgAmplitude,newPhase);
81  }
82 
85  {
87  fPhase += rhs.fPhase;
88  return *this;
89  }
90 
93  {
95  fPhase -= rhs.fPhase;
96  return *this;
97  }
98 
99  // should this operator use Test<CloseTo> instead of operator==?
100  bool operator==(const ComplexLgAmpPhase& rhs) const
101  { return fLgAmplitude == rhs.fLgAmplitude && fPhase == rhs.fPhase; }
102 
104  Pow(double power)
105  {
106  fLgAmplitude *= power;
107  fPhase *= power;
108  return *this;
109  }
110 
111  private:
112  double fLgAmplitude;
113  double fPhase;
114 
115  };
116 
118  inline
120  Interpolate(double x1, const ComplexLgAmpPhase& y1,
121  double x2, const ComplexLgAmpPhase& y2,
122  double x)
123  {
124  const double a1 = y1.GetLgAmplitude();
125  const double p1 = y1.GetPhase();
126  const double a2 = y2.GetLgAmplitude();
127  const double p2 = y2.GetPhase();
128  const double frac = (x - x1) / (x2 - x1);
129  const double anew = a1 + frac * (a2 - a1);
130  const double pnew = p1 + frac * (p2 - p1);
131  return ComplexLgAmpPhase(anew, pnew);
132  }
133 
134 } // utl
135 
136 #endif
double GetAmplitude() const
Get the amplitude.
constexpr double Interpolate(const double dx, const double dy, const double x)
double GetImag() const
Get the imaginary part.
ComplexLgAmpPhase operator*(const ComplexLgAmpPhase &rhs) const
double GetPhase() const
Get the phase in radians, can be bigger than 2*pi.
std::complex< double > GetComplex() const
Get the complex number in standard notation; this clips the phase to 2*pi!
ComplexLgAmpPhase & operator/=(const ComplexLgAmpPhase &rhs)
double pow(const double x, const unsigned int i)
const phoenix::function< PowerToImpl > power
Definition: UnitGrammar.h:47
ComplexLgAmpPhase & operator*=(const ComplexLgAmpPhase &rhs)
double GetReal() const
Get the real part.
bool operator==(const ComplexLgAmpPhase &rhs) const
A class to store complex numbers which are internally represented by log10(amplitude) and phase (and ...
double GetLgAmplitude() const
Get log10(amplitude)
ComplexLgAmpPhase(const double lgamp, const double phase=0)
Constructor using log10(amplitude) and phase (in radians)
ComplexLgAmpPhase()
Standard constructor initializing to zero.
ComplexLgAmpPhase operator/(const ComplexLgAmpPhase &rhs) const
ComplexLgAmpPhase & Pow(double power)

, generated on Tue Sep 26 2023.