Documentation

This is machine translation

Translated by Microsoft
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.

wavetableSynthesizer System object

Generate periodic signal from single-cycle waveforms

Description

The wavetableSynthesizer System object™ generates a periodic signal with tunable properties. The periodic signal is defined by a single-cycle waveform cached as the Wavetable property of your wavetableSynthesizer object.

To generate a periodic signal:

  1. Create the wavetableSynthesizer object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Syntax

waveSynth = wavetableSynthesizer
waveSynth = wavetableSynthesizer(wavetableValue)
waveSynth = wavetableSynthesizer(wavetableValue,frequencyValue)
waveSynth = wavetableSynthesizer(___,Name,Value)

Description

waveSynth = wavetableSynthesizer creates a wavetable synthesizer System object, waveSynth, with default property values.

waveSynth = wavetableSynthesizer(wavetableValue) sets the Wavetable property to wavetableValue.

waveSynth = wavetableSynthesizer(wavetableValue,frequencyValue) sets the Frequency property to frequencyValue.

waveSynth = wavetableSynthesizer(___,Name,Value) sets each property Name to the specified Value. Unspecified properties have default values.

Example: waveSynth = wavetableSynthesizer('Amplitude',2,'DCOffset',2.5) creates a System object, waveSynth, that generates the default sine waveform with an amplitude of 2 and a DC offset of 2.5.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Single-cycle waveform, specified as a vector of real values. The algorithm of the wavetableSynthesizer indexes into the single-cycle waveform to synthesize a periodic wave.

This property is semi-tunable. You can tune the values of the wavetable when the object is locked. However, you cannot tune the length of the wavetable when the object is locked.

Tunable: Yes

Data Types: single | double

Frequency of generated signal in Hz, specified as a real scalar greater than or equal to 0.

Tunable: Yes

Data Types: single | double

Amplitude of generated signal, specified as a real scalar greater than or equal to 0.

The generated signal is multiplied by the value specified by Amplitude at the output, before DCOffset is applied.

Tunable: Yes

Data Types: single | double

Normalized phase offset of generated signal, specified as a real scalar with values in the range [0, 1]. The range is a normalized 2π radians interval.

Tunable: No

Data Types: single | double

Value added to each element of the generated signal, specified as a real scalar.

Tunable: Yes

Data Types: single | double

Number of samples per frame, specified as a positive integer in the range [1, 192000].

This property determines the vector length that your wavetableSynthesizer object outputs.

Tunable: Yes

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Sample rate of generated signal in Hz, specified as a real positive scalar.

Tunable: Yes

Data type of generated signal, specified as 'double' or 'single'.

Tunable: No

Data Types: char

Usage

For versions earlier than R2016b, use the step function to run the System object™ algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

waveform = waveSynth()

Description

example

waveform = waveSynth() generates a periodic signal, waveform. The type of signal is specified by the algorithm and properties of the wavetableSynthesizer System object, waveSynth.

Output Arguments

expand all

Waveform output from the wavetable synthesizer, returned as a column vector with length specified by the SamplesPerFrame property and data type specified by the OutputDataType property.

Data Types: single | double

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)
createAudioPluginClassCreate audio plugin class that implements functionality of System object
configureMIDIConfigure MIDI connections between audio object and MIDI controller
disconnectMIDIDisconnect MIDI controls from audio object
getMIDIConnectionsGet MIDI connections of audio object
cloneCreate duplicate System object
isLockedDetermine if System object is locked
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object
stepRun System object algorithm

The createAudioPluginClass and configureMIDI functions map tunable properties of the wavetableSynthesizer System object to user-facing parameters:

PropertyRangeMappingUnit
Frequency[0.1, 20000]logHz
Amplitude[0, 10]linearnone
DCOffset[–10, 10]linearnone

Examples

expand all

Define and plot a single-cycle waveform.

values = -1:0.1:1;
singleCycleWave = ones(100,1) * values;
singleCycleWave = reshape(singleCycleWave,numel(singleCycleWave),1);

plot(singleCycleWave)
xlabel('Index')
ylabel('Amplitude')

Create a wavetable synthesizer, waveSynth, to generate a staircase wave using the single-cycle waveform. Specify a frequency of 10 Hz.

waveSynth = wavetableSynthesizer(singleCycleWave,10);

Create a time scope to visualize the staircase wave generated by waveSynth.

scope = dsp.TimeScope( ...
    'SampleRate',waveSynth.SampleRate, ...
    'TimeSpan',0.1, ...
    'YLimits',[-1.5,1.5], ...
    'TimeSpanOverrunAction','Scroll', ...
    'ShowGrid',true, ...
    'Title','Variable-Frequency Staircase Wave');

Place the wavetable synthesizer in an audio stream loop. Increase the frequency of your staircase wave in 10 Hz increments.

counter = 0;
while (counter < 1e4)
    counter = counter + 1;
    staircaseWave = waveSynth();
    scope(staircaseWave)
    if mod(counter,1000)==0
        waveSynth.Frequency = waveSynth.Frequency + 10;
    end
end

Sample an audio file and save it to the Wavetable property of a wavetableSynthesizer System object™. Use the wavetable synthesizer to manipulate your audio sample.

Read in an entire audio file. Clip out an interesting sound from the audio and then play it.

[audio,fs] = audioread('MainStreetOne-24-96-stereo-63secs.wav');

engine = audio(5.35e6:5.45e6);
sound(engine,fs)

Create a wavetable synthesizer using your audio clip. The duration of the engine audio clip is numel(engine)/fs seconds. In the wavetableSynthesizer, set the Frequency property to 1/(clip duration). The generated signal now plays back at the same rate it was recorded at.

duration = numel(engine)/fs;
waveSynth = wavetableSynthesizer('Wavetable',engine,'SampleRate',fs, ...
    'Frequency',1/duration);

Create an audioDeviceWriter to write to your audio device.

deviceWriter = audioDeviceWriter('SampleRate',fs);

In a loop, play the wavetable synthesizer to your device. After three seconds, begin increasing the frequency of the wavetable synthesizer. After six seconds, begin decreasing the frequency of the wavetable synthesizer.

timeElapsed = 0;
while timeElapsed < 9
    audioWave = waveSynth();
    deviceWriter(audioWave);

    if (timeElapsed > 3) && (timeElapsed < 6)
        waveSynth.Frequency = waveSynth.Frequency + 0.001;
    elseif timeElapsed > 6
        waveSynth.Frequency = waveSynth.Frequency - 0.002;
    end

    timeElapsed = timeElapsed + waveSynth.SamplesPerFrame*(1/fs);
end

Modify the Wavetable property of a wavetableSynthesizer System object™ while stream processing. Visualize the wavetable and play the resulting audio.

Create a single-cycle waveform for the wavetableSynthesizer to index into. Create a wavetable synthesizer object.

t = 0:0.001:1;
exponent = 5;
waveTable = [t.^exponent,fliplr(t.^exponent)] - 0.5;

waveSynth = wavetableSynthesizer('Wavetable',waveTable);

Create a dsp.ArrayPlot object to plot the wavetable as it is modified over time. Create an audioDeviceWriter object to listen to the signal output by your wavetable synthesizer.

arrayPlotter = dsp.ArrayPlot('YLimits',[-1,1],'PlotType','Line');
deviceWriter = audioDeviceWriter;

In an audio stream loop, incrementally modify the Wavetable property of the wavetable synthesizer and plot it. Call the synthesizer to output a waveform and play the waveform to your audio device.

tic
while toc < 10
    exponent = exponent - 0.01;
    waveSynth.Wavetable = [t.^abs(exponent),fliplr(t.^abs(exponent))] - 0.5;

    arrayPlotter(waveSynth.Wavetable')

    deviceWriter(waveSynth());
end

release(deviceWriter)

Algorithms

expand all

The wavetableSynthesizer System object synthesizes periodic signals using a cached single-cycle waveform, specified waveform properties, and phase memory.

Extended Capabilities

See Also

System Objects

Introduced in R2016a

Was this topic helpful?