Documentation

fgen

Create Quick-Control Function Generator object

Syntax

myFGen = fgen()
connect(myFGen);
set(myFGen, 'P1',V1,'P2',V2,...)
enableOutput(myFGen);

Description

The Quick-Control Function Generator can be used for any function generator that uses an underlying IVI-C driver. However, you do not have to directly deal with the underlying driver. This fgen object is easy to use.

myFGen = fgen() creates an instance of the function generator named myFGen.

connect(myFGen); connects to the function generator.

set(myFGen, 'P1',V1,'P2',V2,...) assigns the specified property values.

enableOutput(myFGen); enables the function generator to produce a signal that appears at the output connector.

For information on the prerequisites for using fgen, see Quick-Control Function Generator Prerequisites.

The Quick-Control Function Generator fgen function can use the following special functions, in addition to standard functions such as connect and disconnect.

FunctionDescription
selectChannel

Specifies the channel name from which the function generator produces the waveform.

Example:

 selectChannel(myFGen, '1');
getDrivers

Returns a list of available function generator instrument drivers.

Example:

drivers = getDrivers(myFGen);
getResources

Retrieves a list of available instrument resources. It returns a list of available VISA resource strings when using an IVI-C function generator.

Example:

res = getResources(myFGen);
selectWaveform

Specifies which arbitrary waveform the function generator produces.

Example:

selectWaveform (myFGen, wh);

where wh is the waveform handle you are selecting.

downloadWaveform

Downloads an arbitrary waveform to the function generator. If you provide an output variable, a waveform handle is returned. It can be used in the selectWaveform and removeWaveform functions.

If you don't provide an output variable, function generator will overwrite the waveform when a new waveform is downloaded and deletes it upon disconnection.

Example:

 % To download the following waveform to fgen
 w = 1:0.001:2;
 downloadWaveform (myFGen, w);
 % To download a waveform to fgen and return a 
    waveform handle
 wh = downloadWaveform (myFGen, w);
removeWaveform

Removes a previously created arbitrary waveform from the function generator's memory. If a waveform handle is provided, it removes the waveform represented by the waveform handle.

Example:

 % Remove a waveform from fgen with waveform 
     handle 10000
  removeWaveform (myFGen, 10000);
enableOutput

Enables the function generator to produce a signal that appears at the output connector. This function produces a waveform defined by the Waveform property. If the Waveform property is set to 'Arb', the function uses the latest internal waveform handle to output the waveform.

enableOutput (myFGen);
disableOutput

Disables the signal that appears at the output connector. Disables the selected channel.

disableOutput (myFGen);
reset

Sets the function generator to factory state.

Arguments

The Quick-Control Function Generator fgen can use the following properties.

Property Description
AMDepth

Specifies the extent of Amplitude modulation the function generator applies to the carrier signal. The units are a percentage of full modulation. At 0% depth, the output amplitude equals the carrier signal's amplitude. At 100% depth, the output amplitude equals twice the carrier signal's amplitude. This property affects function generator behavior only when the Mode is set to 'AM' and ModulationResource is set to 'internal'.

Amplitude

Specifies the amplitude of the standard waveform. The value is the amplitude at the output terminal. The units are volts peak-to-peak (Vpp). For example, to produce a waveform ranging from -5.0 to +5.0 volts, set this value to 10.0 volts. Does not apply if Waveform is of type 'Arb'.

ArbWaveformGain

Specifies the factor by which the function generator scales the arbitrary waveform data. Use this property to scale the arbitrary waveform to ranges other than -1.0 to +1.0. When set to 2.0, the output signal ranges from -2.0 to +2.0 volts. Only applies if Waveform is of type 'Arb'.

BurstCount

Specifies the number of waveform cycles that the function generator produces after it receives a trigger. Only applies if Mode is set to 'burst'.

ChannelNames

This read-only property provides available channel names in a cell array.

Driver

This property is optional. Use only if necessary to specify the underlying driver used to communicate with an instrument. If the DriverDetectionMode property is set to 'manual', use the Driver property to specify the instrument driver.

DriverDetectionMode

Sets up criteria for connection. Valid values are 'auto' and 'manual'. The default value is 'auto', which means you do not need to set a driver name before connecting to an instrument. If set to 'manual', a driver name needs to be provided using the Driver property before connecting to instrument.

FMDeviation

Specifies the maximum frequency deviation the modulating waveform applies to the carrier waveform. This deviation corresponds to the maximum amplitude level of the modulating signal. The units are Hertz (Hz). This property affects function generator behavior only when Mode is set to 'FM' and ModulationSource is set to 'internal'.

Frequency

Specifies the rate at which the function generator outputs an entire arbitrary waveform when Waveform is set to 'Arb'. It specifies the frequency of the standard waveform when Waveform is set to standard waveform types. The units are Hertz (Hz).

Mode

Specifies run mode. Valid values are 'continuous', 'burst', 'AM', or 'FM'. Specifies how the function generator produces waveforms. It configures the instrument to generate output continuously or to generate a discrete number of waveform cycles based on a trigger event. It can also be set to AM and FM.

ModulationFrequency

Specifies the frequency of the standard waveform that the function generator uses to modulate the output signal. The units are Hertz (Hz). This attribute affects function generator behavior only when Mode is set to 'AM' or 'FM' and the ModulationSource attribute is set to 'internal'.

ModulationSource

Specifies the signal that the function generator uses to modulate the output signal. Valid values are 'internal' and 'external'. This attribute affects function generator behavior only when Mode is set to 'AM' or 'FM'.

ModulationWaveform

Specifies the standard waveform type that the function generator uses to modulate the output signal. This affects function generator behavior only when Mode is set to 'AM' or 'FM' and the ModulationSource is set to 'internal'. Valid values are 'sine', 'square', 'triangle', 'RampUp', 'RampDown', and 'DC'.

Offset

Uses the standard waveform DC offset as input arguments if the waveform is not of type 'Arb'. Use Arb Waveform Offset as input arguments if the waveform is of type 'Arb'.

Specifies the DC offset of the standard waveform when Waveform is set to standard waveform. For example, a standard waveform ranging from +5.0 volts to 0.0 volts has a DC offset of 2.5 volts. When Waveform is set to 'Arb', this property shifts the arbitrary waveform's range. For example, when it is set to 1.0, the output signal ranges from 2.0 volts to 0.0 volts.

OutputImpedance

Specifies the function generator's output impedance at the output connector.

Resource

Set this before connecting to the instrument. It is the VISA resource string for your instrument.

SelectedChannelReturns the selected channel name that was set using the selectChannel function.
StartPhase

Specifies the horizontal offset in degrees of the standard waveform the function generator produces. The units are degrees of one waveform cycle. For example, a 180-degree phase offset means output generation begins halfway through the waveform.

Status

This read-only property indicates the communication status of your instrument session. It is either 'open' or 'closed'.

TriggerRate

Specifies the rate at which the function generator's internal trigger source produces a trigger, in triggers per second. This property affects function generator behavior only when the TriggerSource is set to 'internal'. Only applies if Mode is set to 'burst'.

TriggerSource

Specifies the trigger source. After the function generator receives a trigger, it generates an output signal if Mode is set to 'burst'. Valid values are 'internal' or 'external'.

Waveform

Uses the waveform type as an input argument. Valid values are 'Arb', for an arbitrary waveform, or these standard waveform types – 'Sine', 'Square', 'Triangle', 'RampUp', 'RampDown', and 'DC'.

Examples

Create an instance of the function generator called myFGen.

myFGen = fgen()

Discover available resources. A resource string is an identifier to the instrument. You need to set it before connecting to the instrument.

availableResources = getResources(myFGen)

Set the resource. In this example, we are controlling an instrument that is connected via GPIB with a board index of 0 and primary address of 10.

myFGen.Resource = 'GPIB0::10::INSTR';

Connect to the function generator.

connect(myFGen);

Specify the channel name from which the function generator produces the waveform.

selectChannel(myFGen, '1');

Configure a standard waveform to be a continuous sine wave.

set(myFGen, 'Waveform', 'sine');
set(myFGen, 'Mode', 'continuous');

Configure the function generator.

% Set the load impedance to 50 Ohms. 
set(myFGen, 'OutputImpedance', 50);

% Set the frequency to 2500 Hz. 
set(myFGen, 'Frequency', 2500);

% Set the amplitude to 1.2 volts. 
set(myFGen, 'Amplitude', 1.2);

% Set the offset to 0.4 volts. 
set(myFGen, 'Offset', 0.4);

Communicate with the instrument. For example, output signals. In this example, the enableOutput function enables the function generator to produce a signal that appears at the output connector.

% Enable the output of signals. 
enableOutput(myFGen);

When you are done, disable the output.

% Disable the output of signals. 
disableOutput(myFGen);

Close the session and remove it from the workspace.

disconnect(myFGen);
delete myFGen;
clear myFGen;

These examples used a standard waveform type. For examples using an arbitrary waveform, see Generating Waveforms Using the Quick-Control Function Generator.

Was this topic helpful?