Skip to main content
Skip table of contents

SineGenControlFract32

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.

Internally, the module uses complex rotation around the unit circle to achieve the sine and cosine outputs. The complex vector [stateReal stateImag] has unity magnitude and is repeatedly multiplied by another unity magnitude complex vector [incReal incImag]. [incReal incImag] is computed at the start of each block process using the value on the input pin. Only the first sample from the input pin is used as the frequency and this frequency is applied across the entire block.

[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
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

Data type: float

Channel range: 1

Block size range: Unrestricted

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

CODE
 M=sine_gen_control_fract32_module(NAME, SR, BLOCKSIZE, ISQUAD)
 Creates a sine wave generator with a control input pin.  This
 module has a floating-point input pin that specifies the frequency in
 Hz and a fract32 output pin with the generated signal.  Arguments:
    NAME - name of the module.
    SR - sample rate
    BLOCKSIZE - number of samples per output channel.
    ISQUAD - An optional Boolean forth argument specifies that this
           is a quadrature oscillator with a stereo output pin.  The
           first output channel is the cosine portion; the second
           output channel is the sine portion.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.