SoDaRadio-5.0.3-master:8901fb5
QuadratureOscillator.hxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012,2013,2014 Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef QUADOSC_HDR
30 #define QUADOSC_HDR
31 #include <complex>
32 #include <math.h>
33 
34 
35 namespace SoDa {
40  public:
45  idx = 0;
46  ang = 0.0;
47  // default IF freq is SampRate/1000;
48  setPhaseIncr(2.0 * M_PI / 1000.0);
49  }
50 
63  std::complex<double> stepOscCD() {
64  double s,c;
65 #if __linux__
66  sincos(ang, &s, &c);
67 #else
68  s = sin(ang); c = cos(ang);
69 #endif
70  ang = (ang > M_PI) ? (ang - (2.0 * M_PI)) : ang;
71  idx = 0;
72 
73  idx++;
74  ang += phase_incr;
75  s = -s;
76  std::complex<double> ret(c, s);
77  return ret;
78  }
79 
86  std::complex<float> stepOscCF() {
87  std::complex<double> dv = stepOscCD();
88  std::complex<float> fv((float)dv.real(), (float)dv.imag());
89  return fv;
90  }
91 
98  double stepOscD() {
99  std::complex<double> dv = stepOscCD();
100  return dv.real();
101  }
102 
107  void setPhaseIncr(double _pi) {
108  phase_incr = _pi;
109  }
110 
111  private:
112  double phase_incr;
113  double ang;
114  int idx;
115  };
116 }
117 
118 #endif
void setPhaseIncr(double _pi)
set the phase increment per step for the oscillator (1/freq)
std::complex< double > stepOscCD()
step the oscillator and produce a complex double result
std::complex< float > stepOscCF()
step the oscillator and produce a complex float result
sin/cos oscillator to drive TX signal chain
double stepOscD()
step the oscillator and produce a real double result