This is machine translation

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

dsp.SineWave System object

Package: dsp

Discrete-time sinusoid


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:


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:


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.


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.



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


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.


Indicates whether the sine wave is complex or real

Set to true to output a complex exponential. The default value is false.


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.


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.


Sampling rate for the sine wave

Specify the sampling rate of the output, in hertz, as a positive numeric scalar. The default is 1000.


Number of samples per frame

Specify the number of consecutive samples from each sinusoid to buffer into the output frame. The default is 1.


Output data type

Specify the output data type as double, single, or Custom. The default value is double.

 Fixed-Point Properties


cloneCreate sine wave object with same property values
isLockedLocked status for input attributes and nontunable properties
releaseAllow property value and input characteristics changes
resetReset sine wave to the beginning
stepDiscrete-time sine wave


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.

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

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 = hsin2();


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?