Sine Cosine Generator
Overview
sin_cos_gen
is an oscillator that simultaneously generates sine and cosine waveforms. sin_cos_gen
is implemented utilizing Hal Chamberlin’s state variable IIR filter, a digital derivation of the analog state variable filter optimized for infinite Q oscillation. sin_cos_gen
is suitable as a low frequency sine wave oscillator. The upper frequency limit for stability is roughly 1/6 sps. At low frequencies, the waveform symmetry is very pure, but it becomes skewed as you approach the upper limit. For low frequencies, we can reduce the calculation of the coefficient to 2*Pi*freq/sps. When utilized with fixed point or IEEE floating point, the oscallator should run forever without instability.
While sin_cos_gen
is technically an oscillator which generates periodic waveforms, it is presented as a model of Generator
because it does not conform to the Oscillator
concept which requires complete control over the phase
.
Although sin_cos_gen
is technically an oscillator that produces periodic waveforms, it is represented as a model of a Generator
because it does not adhere to the Oscillator
concept, which requires complete control over the phase
for synchronicity. As a free-running oscillator,sin_cos_gen
can exhibit phase drift over time due to accumulating floating-point errors.
Declaration
struct sin_cos_gen
{
sin_cos_gen(frequency f, float sps);
std::pair<float, float> operator()();
void config(frequency f, float sps);
void reset(float sin = 0.0f, float cos = 1.0f);
void midpoint();
};
Expressions
sin_cos_gen
is a model of Generator
. In addition to valid expressions for Generator
, sin_cos_gen
allows these expressions.
Notation
g
-
Object of type
sin_cos_gen
. f
-
Object of type
frequency
. sps
-
Floating point value representing samples per second.
sval
,cval
-
Floating point value values.
Constructor
Expression | Semantics |
---|---|
|
Construct |
C++ brace initialization may also be used. |
Function Call
Expression | Semantics | Return Type |
---|---|---|
|
Generate a sin/cos signal and get
both |
|
|
Generate a sin/cos signal and get
only the |
|
|
Generate a sin/cos signal and get only the |
|