OpenWareLaboratory
QuadratureSineOscillator.h
Go to the documentation of this file.
1 #ifndef QUADRATURE_SINE_OSCILLATOR_H
2 #define QUADRATURE_SINE_OSCILLATOR_H
3 
4 #include "ComplexOscillator.h"
5 
11 class QuadratureSineOscillator : public ComplexOscillatorTemplate<QuadratureSineOscillator> {
12 public:
13  static constexpr float begin_phase = 0;
14  static constexpr float end_phase = 2 * M_PI;
16  return ComplexFloat { cosf(phase), sinf(phase) };
17  }
18  void generate(ComplexFloatArray output) {
19  size_t len = output.getSize();
20  for (size_t i = 0; i < len; ++i) {
21  output[i].re = cosf(phase);
22  output[i].im = sinf(phase);
23  phase += incr; // allow phase to overrun
24  }
25  phase = fmodf(phase, end_phase);
26  }
28  size_t len = output.getSize();
29  for (size_t i = 0; i < len; ++i) {
30  output[i].re = cosf(phase);
31  output[i].im = sinf(phase);
32  phase += incr * (1 + fm[i]);
33  // allow phase to overrun
34  }
35  phase = fmodf(phase, end_phase);
36  }
38 };
39 
45 class FeedbackQuadratureSineOscillator : public ComplexOscillatorTemplate<FeedbackQuadratureSineOscillator> {
46 public:
47  static constexpr float begin_phase = 0;
48  static constexpr float end_phase = 2 * M_PI;
49  void setFeedback(float feedback) {
50  this->feedback = feedback;
51  }
52  float getFeedback() const {
53  return feedback;
54  }
57  cosf(phase + last_sample.re * feedback), sinf(phase + last_sample.im * feedback));
58  return last_sample;
59  }
60  void generate(ComplexFloatArray output) {
61  size_t len = output.getSize();
62  for (size_t i = 0; i < len; ++i) {
63  output[i].re = cosf(phase + last_sample.re * feedback);
64  output[i].im = sinf(phase + last_sample.im * feedback);
65  last_sample = output[i];
66  phase += incr; // allow phase to overrun
67  }
68  phase = fmodf(phase, end_phase);
69  }
71  size_t len = output.getSize();
72  for (size_t i = 0; i < len; ++i) {
73  output[i].re = cosf(phase + last_sample.re * feedback);
74  output[i].im = sinf(phase + last_sample.im * feedback);
75  last_sample = output[i];
76  phase += incr * (1 + fm[i]);
77  // allow phase to overrun
78  }
79  phase = fmodf(phase, end_phase);
80  }
82 protected:
83  float feedback = 0;
85 };
86 
87 
93 class ComplexFeedbackQuadratureSineOscillator : public ComplexOscillatorTemplate<ComplexFeedbackQuadratureSineOscillator> {
94 public:
95  static constexpr float begin_phase = 0;
96  static constexpr float end_phase = 2 * M_PI;
98  this->feedback = feedback;
99  }
101  return feedback;
102  }
105  cosf(phase + last_sample.re * feedback.re), sinf(phase + last_sample.im * feedback.im));
106  return last_sample;
107  }
109  size_t len = output.getSize();
110  for (size_t i = 0; i < len; ++i) {
111  output[i].re = cosf(phase + last_sample.re * feedback.re);
112  output[i].im = sinf(phase + last_sample.im * feedback.im);
113  last_sample = output[i];
114  phase += incr; // allow phase to overrun
115  }
116  phase = fmodf(phase, end_phase);
117  }
119  size_t len = output.getSize();
120  for (size_t i = 0; i < len; ++i) {
121  output[i].re = cosf(phase + last_sample.re * feedback.re);
122  output[i].im = sinf(phase + last_sample.im * feedback.im);
123  last_sample = output[i];
124  phase += incr * (1 + fm[i]);
125  // allow phase to overrun
126  }
127  phase = fmodf(phase, end_phase);
128  }
130 protected:
133 };
134 
135 #endif /* QUADRATURE_SINE_OSCILLATOR_H */
#define M_PI
Definition: basicmaths.h:52
An oscillator similar to QuadratureSineOscillator class that also includes feedback control.
void generate(ComplexFloatArray output, FloatArray fm)
float im(const int i)
Get the imaginary part of an element of the array.
float re(const int i)
Get the real part of an element of the array.
An oscillator similar to QuadratureSineOscillator class that also includes feedback control.
void generate(ComplexFloatArray output)
void generate(ComplexFloatArray output, FloatArray fm)
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
Oscillator outputs complex numbers on unit cycle.
static constexpr float end_phase
static constexpr float begin_phase
void generate(ComplexFloatArray output, FloatArray fm)
void generate(ComplexFloatArray output)
size_t getSize() const
Definition: SimpleArray.h:31
A structure defining a floating point complex number as two members of type float.
float im
The imaginary part of the complex number.
float re
The real part of the complex number.