US English (US)
JP Japanese
CN Chinese
KR Korean

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Knowledge Base Home
  • Contact Us
English (US)
US English (US)
JP Japanese
CN Chinese
KR Korean
  • Home
  • Python API

Using Python to generate arbitrary waveforms while observing the output signal

Written by Paul Cracknell

Updated at December 18th, 2023

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Moku:Go
    Moku:Go General Moku:Go Arbitrary Waveform Generator Moku:Go Data Logger Moku:Go Digital Filter Box Moku:Go FIR Filter Builder Moku:Go Frequency Response Analyzer Moku:Go Logic Analyzer & Pattern Generator Moku:Go Oscilloscope & Voltmeter Moku:Go PID Controller Moku:Go Spectrum Analyzer Moku:Go Waveform Generator Moku:Go Power Supplies Moku:Go Lock-in Amplifier Moku:Go Time & Frequency Analyzer Moku:Go Laser Lock Box Moku:Go Phasemeter
  • Moku:Lab
    Moku:Lab General Moku:Lab Arbitrary Waveform Generator Moku:Lab Data Logger Moku:Lab Digital Filter Box Moku:Lab FIR Filter Builder Moku:Lab Frequency Response Analyzer Moku:Lab Laser Lock Box Moku:Lab Lock-in Amplifier Moku:Lab Oscilloscope Moku:Lab Phasemeter Moku:Lab PID Controller Moku:Lab Spectrum Analyzer Moku:Lab Time & Frequency Analyzer Moku:Lab Waveform Generator Moku:Lab Logic Analyzer/Pattern Generator
  • Moku:Pro
    Moku:Pro General Moku:Pro Arbitrary Waveform Generator Moku:Pro Data Logger Moku:Pro Frequency Response Analyzer Moku:Pro Oscilloscope Moku:Pro PID Controller Moku:Pro Spectrum Analyzer Moku:Pro Waveform Generator Moku:Pro Lock-in Amplifier Moku:Pro Laser Lock Box Moku:Pro Digital Filter Box Moku:Pro FIR Filter Builder Moku:Pro Phasemeter Moku:Pro Multi-instrument Mode Moku:Pro Logic Analyzer/Pattern Generator Moku:Pro Time & Frequency Analyzer
  • Python API
  • MATLAB API
  • Arbitrary Waveform Generator
  • Data Logger
  • Digital Filter Box
  • FIR Filter Builder
  • Frequency Response Analyzer
  • Laser Lock Box
  • Lock-in Amplifier
  • Oscilloscope
  • Phasemeter
  • PID Controller
  • Spectrum Analyzer
  • Time & Frequency Analyzer
  • Waveform Generator
  • Logic Analyzer & Pattern Generator
  • Multi Instrument Mode
  • Moku Cloud Compile
  • Moku general
  • LabVIEW
+ More

Table of Contents

Python implementation of Arbitrary Waveform Generator and oscilloscope

Python implementation of Arbitrary Waveform Generator and oscilloscope

Moku's Arbitrary Waveform Generator (AWG) can be deployed within Python to drive output signals. At the same time, the Python AWG can be used as an oscilloscope to view the output signal. In order to do so, you would need to loop back output 1 to input 1.

This is implemented in the Python below :

#
# Moku example: Plotting Oscilloscope with Artibrary Waveform Generator
#
# This example demonstrates how you can configure the ArbitraryWaveformGenerator instrument,
# and view triggered time-voltage data frames in real-time.
#
# (c) 2023 Liquid Instruments Pty. Ltd.
#
from moku.instruments import ArbitraryWaveformGenerator, MultiInstrument, Oscilloscope

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

# Launch MiM and connect to your device through IP
m = MultiInstrument('192.168.###.###', force_connect=True, platform_id=4)
awg = m.set_instrument(1, ArbitraryWaveformGenerator)
awg.set_defaults()
osc = m.set_instrument(2, Oscilloscope)
osc.set_defaults()
connections = [dict(source="Slot1OutA", destination="Slot2InB"),
               dict(source="Slot1OutA", destination="Output1"),
               dict(source="Slot2OutA", destination="Slot2InA")]
m.set_connections(connections=connections)

current_sine = np.zeros(1000)

g = 0
for x in current_sine:
    current_sine[g] = np.sin((float(g)*2*np.pi/len(current_sine)))
    g +=1

try:
    # Generate an output sinewave on Channel 2, 500mVpp, 1MHz, 0V offset
    awg.generate_waveform(channel=1, frequency=1e6, amplitude = 0.5, sample_rate='Auto', lut_data=list(current_sine), interpolation = True) 


    # Trigger on input Channel 2, rising edge, 0V with 0.1V hysteresis)
    osc.set_trigger(source='ChannelA', type="Edge", level=0, hysteresis=0.1)

    # View +-5usec, i.e. trigger in the centre
    osc.set_timebase(-5e-6, 5e-6)

    osc.generate_waveform(1, 'Sine', amplitude=0.5, frequency=1e6, symmetry=0.0)


    # Get initial data frame to set up plotting parameters. This can be done once
    # if we know that the axes aren't going to change (otherwise we'd do
    # this in the loop)
    plt_dt = osc.get_data()

    # Set up the plotting parameters
    plt.ion()
    plt.show()
    plt.grid(True)
    plt.ylim([-1,1])
    plt.xlim([plt_dt['time'][0], plt_dt['time'][-1]])

    line1, = plt.plot([])
    line2, = plt.plot([])

    ax=plt.gca()

    # This loops continuously updates the plot with new data
    while True:
        # Get new data
        data = osc.get_data()

        # Update the plot
        line1.set_ydata(data['ch1'])
        line1.set_xdata(data['time'])
        line2.set_ydata(data['ch2'])
        line2.set_xdata(data['time'])
        plt.pause(0.001)

except Exception as e:
        print(f'Exception occured: {e}')

finally:
    # Close the connection to the Moku device
    # This ensures network resources and released correctly
    m.relinquish_ownership()
arbitrary awg generator oscilloscope python waveform moku:lab

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Python Spectrum analyzer 'Max hold' function

Sitemap

  • Moku:Lab
  • Instruments
  • Software
  • Company
  • Support
  • Store
  • Terms & Conditions
  • Privacy Policy

Offices

United States
+1 (619) 332-6230
12526 High Bluff Dr
Suite 150
San Diego, CA 92130

Australia
+61 2 6171 9730
243 Northbourne Avenue
Suite 2
Lyneham, ACT 2602

Australia
+61 03 7073 3594
700 Swanston Street
Suite 5E, Level 5
Carlton, VIC 3053

Follow us

Youtube LinkedIn

官方微信

Contact us
© 2025 Liquid Instruments. All rights reserved.

Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand