Creating custom analog waveforms

The five Wire Waveform Source is an arbitrary waveform generator (AWG). To simplify the user experience the GUI includes standard waveforms such as sine, square,  triangle, RC, battery, and DC with settable parameters such as frequency/period, duty cycle, amplitude, etc. The standard waveforms are easy to use but do not show the full power of the Waveform Source.

The Waveform Source generates 0 – 5 V output with 10 bits of resolution. Up to 1020 points can be defined each having a duration from 1 us to hundreds of seconds each. Just like the Logic Source, the Waveform source includes 3 jump controllers providing branch and counted loop control. You can easily generate a custom waveform using the MBScript scripting language. In our first example we will write a script which creates a square wave by combing the fundamental, 3rd, 5th, 7th, and 9th harmonics of a 1KHz sine wave.

The script defines a function waveValue() to calculate the signal magnitude at each point. This includes a 2.5 V offset to center the waveform and the fundamental sine wave and its odd harmonics scaled according to the Fourier series. The pattern includes 630 points with factors of 2 x 3 x 3 x 5 x 7 ensuring that complete integral cycles of each harmonic can be created. A for() loop sets the first 659 points by calling the function setPoint(). The last point is created with a jumpA command which is configured to branch back to the beginning of the waveform in an infinite loop. Here is the complete script.


// Include the WS_Lib.mbs library
addLibrary scriptDirectory + “WS_Lib.mbs”;

// Waveform parameters
fundamental = 1e3; // fundamental frequency is 1KHz

points = 630; // 2*3*3*5*7 = number of waveform points to use
dt = 1/(fundamental*points); // Period of eaach point

// Calculate the magnitude of the waveform at a specific phase
function waveValue(deg)
{
return 2.5 + sin(deg) + ((1/3)*sin(3*deg)) + ((1/5)*sin(5*deg)) + ((1/7)*sin(7*deg)) + ((1/9)*sin(9*deg));
}

SY(“openWindow waveformSource”);

// Generate and load the waveform
for(i=0;i<points;i++)
{
d = i*360/points;
setPoint(i, waveValue(d), dt, “next”);
}

// Create the last point with a jumpA mode
i–;
d = i*360/points;
setPoint(i, waveValue(d), dt, “jumpA”);

// Configure jumpA to always jump to the first point
configJump(“jumpA”, “always”, 0, 1);

// Update the waveform display
update(dt*points);

// Run the waveform
WS(“run”);


Running the script opens the Waveform Source window, loads the waveform, updates the Waveform Display to show its shape in the GUI, and runs the pattern on the Waveform source. Here is a partial screen capture of the Waveform Display view.

Here is a cell phone pic of an oscilloscope display.This shows that it is fairly straight forward to create your own waveforms by replacing the waveValue() function. For example you may want to step between two frequencies inside and outside of a filter pass band. Here is a waveValue() function that toggles between 1KHz and 3KHz

function waveValue(deg)
{
if(deg < 360)
return 2.5 + sin(deg);
else
return 2.5 + sin(3*deg);
}

We configure the A and B jump controllers to repeat each frequency for 100 cycles and the C jump controller branches back to the beginning of the waveform forming an infinite loop. Here is a cell phone scope capture of the frequency transition.

The Waveform Source provides quick easy to use standard waveforms. By writing a little MBScript code you can take full advantage of its AWG features.