Overview
Sine wave generator with frequency taken from a control pin
Discussion
Sine wave generator in which the frequency is taken from an input pin. The module requires setting sample rate and blocksize as input arguments. If the module is instantiated with the optional ISQUAD set to 1, the module will act as a quadrature sine oscillator, with the single output pin sending out the quadrature signal in interleaved form. In quadrature mode, the output contains two interleaved channels. The first channel represents the real portion of the oscillator (cosine) and the second channel represents the imaginary portion (sine). When using the quadrature output, a Deinterleave module can be used following the module to separate the sine and cosine outputs.
...
[stateReal stateImag] represents the instantaneous phase with stateReal representing the cosine output and stateImag representing the sine output. The initial values of [stateReal and stateImag] are determined by the startPhase parameter. startPhase is specified in degrees. The rotation vector [incReal incImag] determines the frequency of the oscillator: $\mathrm{incReal} + j \mathrm{incImag} = e^{\frac{j 2 \pi \mathrm{freq}}{\mathrm{sampleRate}}}$
Type Definition
Code Block |
---|
typedef struct _ModuleSineGenControlFract32 { ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure FLOAT32 smoothingTime; // Time constant of the smoothing process. FLOAT32 startPhase; // Starting phase of the sine wave FLOAT32 currentFreq; // Internal state variable holding the smoothed frequency fract32 stateReal; // Real part of the complex unity magnitude state variable fract32 stateImag; // Imaginary part of the complex unity magnitude state variable FLOAT32 smoothingCoeff; // Smoothing coefficient. } ModuleSineGenControlFract32Class; |
Variables
Properties
Name | Type | Usage | isHidden | Default value | Range | Units |
smoothingTime | float | parameter | 0 | 10 | 0:1000 | msec |
startPhase | float | parameter | 0 | 0 | 0:360 | degrees |
currentFreq | float | state | 0 | 0 | Unrestricted | |
stateReal | fract32 | state | 1 | 1 | Unrestricted | |
stateImag | fract32 | state | 1 | 0 | Unrestricted | |
smoothingCoeff | float | derived | 1 | 0.06449 | Unrestricted |
Pins
Input Pins
Name: freq
Description: Frequency in Hz
...
Sample rate range: Unrestricted
Complex support: Real
Output Pins
Name: out
Description: output data
Data type: fract32
MATLAB Usage
File Name: sine_gen_control_fract32_module.m
...