This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Generate an Arbitrary Waveform Using Waveform Function Generation Channels

This example shows how to use the function generation channel in a session to generate an arbitrary waveform function, at 100kHz frequency. The signal’s output voltage range is set to -5.0 to +5.0 volts

Create a Digilent acquisition session

s = daq.createSession('digilent');

Use daq.getdevices to discover available Digilent devices.

Create a waveform function generation channel with a Arbitrary WaveformType.

fgenCh = addFunctionGeneratorChannel(s, 'AD1', 1, 'Arbitrary')
fgenCh = 

Data acquisition arbirtray waveform generator '1' on device 'AD1':

              Phase: 0
              Range: -5.0 to +5.0 Volts
     TerminalConfig: SingleEnded
               Gain: 1
             Offset: 0
          Frequency: 4096
       WaveformType: Sine
     FrequencyLimit: [0.0 25000000.0]
               Name: ''
                 ID: '1'
             Device: [1x1 daq.di.DeviceInfo]
    MeasurementType: 'Voltage'

Set the buffer size to 4096 and set the channel to generate a waveform repeatedly from the contents of the buffer. The channel outputs for a fixed number of times over the space of the buffer.

buffersize = 4096;
len = buffersize + 1;

f0 = 1;
f1 = 1 * f0;
f3 = 3 * f0;
f5 = 5 * f0;

waveform  = sin(linspace(0, 2*pi*f1, len)) + ...
            sin(linspace(0, 2*pi*f3, len)) + ...
            sin(linspace(0, 2*pi*f5, len));

waveform = 5*waveform./max(abs(waveform));
waveform(end) = [];

Set the WaveformData of the channel to the waveform.

fgenCh.WaveformData = waveform;

Set the frequency of the channel to 100 KHz.

fgenCh.Frequency = 100e3;

Set the session duration to 5 seconds and generate continuous data.

s.DurationInSeconds = 5;