Electric Tiger DAQ  1.0.0
Data Acquisition Software for the Electric Tiger Experiment
test_modecharacterization.h
1 #ifndef TEST_MODECHARACTERIZATION_H
2 #define TEST_MODECHARACTERIZATION_H
3 
4 
5 //C System-Headers
6 //
7 //C++ System headers
8 #include <vector>
9 #include <algorithm>
10 #include <functional>
11 //Qt Headers
12 //
13 //OpenCV Headers
14 //
15 //Boost Headers
16 //
17 //Project specific headers
18 #include "modecharacterization.h"
19 
20 namespace etig {
21 
22 namespace test {
23 
24 double volts_sqr_to_dbm( double voltage ) {
25  return 10.0 * log10( voltage / std::sqrt(0.05) );
26 }
27 
28 struct VoltsSqrTodBm {
29 
30  void operator()(data_triple<double> &data) const {
31  data.power_dBm = volts_sqr_to_dbm( data.power_dBm );
32  }
33 };
34 
35 inline double lorentzian( double f, double Q, double f_0 ) {
36 
37  double fwhm = f_0/Q;
38  double gamma = ( f_0 - f )/( fwhm/2.0 );
39 
40  return 1.0/( 1.0 + gamma*gamma );
41 }
42 
43 
44 void TestModeCharacterization( double f_0, double Q, uint data_size ) {
45 
46  std::vector< data_triple<double> > test_data;
47  test_data.reserve( data_size );
48 
49  std::cout << "Testing mode characretizatipn.\n"
50  << "Test mode has center frequency of "
51  << f_0
52  << " and Q of "
53  << Q
54  << std::endl;
55 
56  for( uint i = 0; i < data_size; i++ ) {
57 
58  double cavity_length = 0.0;
59  double frequency = static_cast<double>( i );
60  double power_dBm = lorentzian( frequency, Q, f_0 );
61 
62  test_data.push_back( data_triple<double>( cavity_length, frequency, power_dBm ) );
63 
64  }
65 
66  std::for_each( test_data.begin(), test_data.end(), VoltsSqrTodBm() );
67 
68  ModeTraits characterization( test_data );
69 
70  double computed_Q = characterization.Q();
71  double computed_f0 = characterization.f0();
72 
73  std::cout << "Computed mode parameters.\n"
74  << "Center frequency of "
75  << computed_f0
76  << " and Q of "
77  << computed_Q
78  << std::endl;
79 }
80 
81 }
82 
83 }
84 
85 #endif // TEST_MODECHARACTERIZATION_H
Definition: algorithm.cpp:16
Definition: test_modecharacterization.h:28
Definition: modecharacterization.h:17
Definition: generics.h:48