Document toolboxDocument toolbox

(8.D.2.2 ) SineGenFract32

Overview

Sine wave generator

Discussion

Sine wave generator, with parameters for controlling frequency and start phase. 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]. [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

typedef struct _ModuleSineGenFract32 { ModuleInstanceDescriptor instance; // Common Audio Weaver module instance structure FLOAT32 freq; // Target frequency of the sine wave FLOAT32 startPhase; // Starting phase of the sine wave fract32 stateReal; // Real part of the complex unity magnitude state variable fract32 stateImag; // Imaginary part of the complex unity magnitude state variable fract32 incReal; // Real part of the complex unity magnitude multiplier fract32 incImag; // Imaginary part of the complex unity magnitude multiplier } ModuleSineGenFract32Class;

Variables

Properties

Name

Type

Usage

isHidden

Default value

Range

Units

freq

float

parameter

0

1000

20:24000

Hz

startPhase

float

parameter

0

0

0:360

degrees

stateReal

fract32

parameter

1

1

Unrestricted

 

stateImag

fract32

parameter

1

0

Unrestricted

 

incReal

fract32

derived

1

0.9914

Unrestricted

 

incImag

fract32

derived

1

0.1305

Unrestricted

 

Pins

Output Pins

Name: out

Description: audio output

Data type: fract32

MATLAB Usage

File Name: sine_gen_fract32_module.m

M=sine_gen_fract32_module(NAME, SR, BLOCKSIZE, ISQUAD) Creates a sine wave generator for use in the Audio Weaver. This module has a single 1 channel output pin with controllable frequency. The output of the module changes instantly when the frequency is updated. Arguments: NAME - name of the module. SR - sample rate BLOCKSIZE - number of samples per output channel. ISQUAD - Boolean specifies that this is a quadrature oscillator with two separate output pins. The first output pin is the cosine portion and the second output pin is the sine portion. Default = 0.

Â