Accelerating the pace of engineering and science

# dsp.SineWave System object

Package: dsp

Discrete-time sinusoid

## Description

The SineWave object generates a discrete-time sinusoid. The sine wave object generates a real–valued sinusoid or a complex exponential. A real-valued, discrete-time sinusoid is defined as:

$y\left(n\right)=A\mathrm{sin}\left(2\pi fn+\varphi \right)$

where A is the amplitude, f is the frequency in hertz, and φ is the initial phase, or phase offset, in radians. A complex exponential is defined as:

$y\left(n\right)=A{e}^{j\left(2\pi fn+\varphi \right)}$

For both real and complex sinusoids, the amplitude, frequency, and phase offsets can be scalars or length-N vectors, where N is the desired number of channels in the output. When you specify at least one of these properties as a length-N vector, scalar values specified for the other properties are applied to each of the N channels.

To generate a discrete-time sinusoid:

1. Define and set up your sine wave. See Construction.

2. Call step to generate the sinusoid according to the properties of dsp.SineWave. The behavior of step is specific to each object in the toolbox.

## Construction

H = dsp.SineWave returns a sine wave object, H, that generates a real-valued sinusoid with an amplitude of 1, a frequency of 100 Hz, and a phase offset of 0. By default, the sine wave object only generates one sample.

H = dsp.SineWave('PropertyName',PropertyValue, ...) returns a sine wave object, H, with each property set to the specified value.

H = dsp.SineWave(AMP,FREQ,PHASE, 'PropertyName',PropertyValue, ...) returns a sine wave object, H, with the Amplitude property set to AMP, the Frequency property set to FREQ, the PhaseOffset property set to PHASE, and the other specified properties set to the specified values.

## Properties

 Amplitude Amplitude of the sine wave Specify the amplitude as a length-N vector containing the amplitudes of the sine waves in each of N output channels, or a scalar to apply to all N channels. The vector length must equal that specified for the Frequency and PhaseOffset properties. The default value is 1. This property is tunable when Method property is Differential or Trigonometric function. Frequency Frequency of the sine wave Specify a length-N vector containing frequencies, in hertz, of the sine waves in each of N output channels, or a scalar to apply to all N channels. The vector length must equal that specified for the Amplitude and PhaseOffset properties. You can specify positive, zero, or negative frequencies. The default is 100. This property is nontunable. PhaseOffset Phase offset of the sine wave in radians A length-N vector containing the phase offsets, in radians, of the sine waves in each of N output channels, or a scalar to apply to all Nchannels. The vector length must equal that specified for the Amplitude and Frequency properties. The default value is 0. This property is nontunable. ComplexOutput Indicates whether the sine wave is complex or real Set to true to output a complex exponential. The default value is false. Method Method used to generate sinusoids The sinusoids are generated by either the Trigonometric function , Table lookup, or Differential methods . The Trigonometric function method computes the sinusoid by sampling the continuous-time sinusoid. The table lookup method precomputes the unique samples of every output sinusoid at the start of the simulation, and recalls the samples from memory as needed. The differential method uses an incremental algorithm. This algorithm computes the output samples based on the output values computed at the previous sample time and precomputed update terms. The default value is Trigonometric function. TableOptimization Optimizes the table of sine values for speed or memory Optimizes the table of sine values for Speed or Memory. When optimized for speed, the table contains k elements, and when optimized for memory, the table contains k/4 elements, where k is the number of input samples in one full period of the sine wave. This property applies only when the Method property is Table lookup. The default value is Speed. SampleRate Sampling rate for the sine wave Specify the sampling rate of the output, in hertz, as a positive numeric scalar. The default is 1000. SamplesPerFrame Number of samples per frame Specify the number of consecutive samples from each sinusoid to buffer into the output frame. The default is 1. OutputDataType Output data type Specify the output data type as double, single, or Custom. The default value is double.

## Methods

 clone Create sine wave object with same property values getNumInputs Number of expected inputs to step method getNumOutputs Number of outputs of step method isLocked Locked status for input attributes and nontunable properties release Allow property value and input characteristics changes reset Reset sine wave to the beginning step Discrete-time sine wave

## Examples

Generate a sine wave with an amplitude of 2, frequency of 10 Hz, and initial phase of 0:

``` hsin1 = dsp.SineWave(2, 10);
hsin1.SamplesPerFrame = 1000;
y = step(hsin1);
plot(y);
```

Generate two sine waves offset by a phase of π/2 radians:

``` hsin2 = dsp.SineWave;
hsin2.Frequency = 10;
hsin2.PhaseOffset = [0 pi/2];
hsin2.SamplesPerFrame = 1000;
y = step(hsin2);
plot(y); ```

## Algorithms

This object implements the algorithm, inputs, and outputs described on the Sine Wave block reference page. The object properties correspond to the block parameters.