1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#ifndef SINUSFITTER_H
#define SINUSFITTER_H
#include <cstring>
#include <cmath>
#include "../structures/types.h"
namespace algorithms {
class SinusFitter {
public:
SinusFitter();
~SinusFitter();
void FindPhaseAndAmplitude(num_t& phase, num_t& amplitude, const num_t* dataX,
const num_t* dataT, const size_t dataSize,
const num_t frequency) const throw();
void FindPhaseAndAmplitudeComplex(num_t& phase, num_t& amplitude,
const num_t* dataR, const num_t* dataI,
const num_t* dataT, const size_t dataSize,
const num_t frequency) const throw();
num_t FindMean(const num_t phase, const num_t amplitude, const num_t* dataX,
const num_t* dataT, const size_t dataSize,
const num_t frequency);
static num_t Value(const num_t phase, const num_t amplitude, const num_t t,
const num_t frequency, num_t mean) {
return std::cos(phase + t * frequency) * amplitude + mean;
}
/*template<typename T> static T Phase(T real, T imaginary)
{
if(real==0.0L)
{
if(imaginary==0.0L)
return 0.0L;
else if(imaginary > 0.0L)
return M_PIn*0.5;
else
return -M_PIn*0.5;
}
else if(real>0.0L)
{
if(imaginary>=0.0L) // first
return atannl(imaginary/real);
else // fourth
return atannl(imaginary/real)+2.0*M_PIn;
}
else
{
if(imaginary>=0.0L) // second
return atannl(imaginary/real) + 1.0*M_PIn;
else // third
return atannl(imaginary/real) + 1.0*M_PIn;
}
}*/
static num_t Phase(num_t real, num_t imaginary) {
return std::atan2(imaginary, real);
}
static numl_t Phase(numl_t real, numl_t imaginary) {
return std::atan2(imaginary, real);
}
private:
};
} // namespace algorithms
#endif
|