# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# 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.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj)``` and `y = obj()` perform equivalent operations.

## Construction

`sine = dsp.SineWave` returns a sine wave object, `sine`, 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.

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

```sine = dsp.SineWave(AMP,FREQ,PHASE, 'PropertyName',PropertyValue, ...)``` returns a sine wave object, `sine`, 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

 reset Reset sine wave to the beginning step Discrete-time sine wave
Common to All System Objects
`clone`

Create System object with same property values

`getNumInputs`

Expected number of inputs to a System object

`getNumOutputs`

Expected number of outputs of a System object

`isLocked`

Check locked states of a System object (logical)

`release`

Allow System object property value changes

## Examples

expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject() becomes step(myObject).

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

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

Generate two sine waves offset by a phase of pi/2 radians.

```sine2 = dsp.SineWave; sine2.Frequency = 10; sine2.PhaseOffset = [0 pi/2]; sine2.SamplesPerFrame = 1000; y = sine2(); 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.

## See Also

#### Introduced in R2012a

Was this topic helpful?

Watch now