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
  • Home
  • Moku:Lab
  • Software integrations
  • Python examples

Using Python to generate arbitrary waveforms while observing the output signal

Written by Paul Cracknell

Updated at February 4th, 2021

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 Arbitrary Waveform Generator Moku:Go Data Logger 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 Digital Filter Box Moku:Go FIR Filter Builder Moku:Go Lock-in Amplifier
  • Moku:Lab
    Windows Moku:Lab general Moku:Lab Instruments iPad app Software integrations
  • Moku:Pro
    Moku:Pro Instruments
+ More

Python implementation of Arbitrary Waveform Generator and oscilloscope

Moku:Lab'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 :

#
# pymoku example: Plotting Oscilloscope with Artibrary Waveform Generator
#
# This example demonstrates how you can configure the ArbWaveGen instrument,
# and view triggered time-voltage data frames in real-time.
#
# (c) 2019 Liquid Instruments Pty. Ltd.
#
from pymoku import *
from pymoku.instruments import Oscilloscope,ArbitraryWaveGen

import numpy as np

import matplotlib
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter

# Connect to your Moku by its device name
# Alternatively, use Moku.get_by_serial('#####') or Moku('192.168.###.###')
m = Moku.get_by_name('Moku')
i = m.deploy_or_connect(ArbitraryWaveGen)


current_sine = np.zeros(1000)
try:

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

i.write_lut(2, current_sine)

# Generate an output sinewave on Channel 2, 500mVpp, 1MHz, 0V offset
i.gen_waveform(2, period = 1.0/1e6, amplitude = 0.5, interpolation = True) 


# Trigger on input Channel 2, rising edge, 0V with 0.1V hysteresis)
i._set_trigger(2, 'rising', 0, None, None, 0.1, False, 'auto')
# View +-5usec, i.e. trigger in the centre
i.set_timebase(-5e-6, 5e-6)

#i.gen_sinewave(2, 0.5, 1e6, 0.0)

# Set the data source of Channel 2 to the generated output sinewave
i._set_source(2, 1)


i.commit()



# 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)
data = i.get_realtime_data()

print(data.ch2)
# Set up the plotting parameters
plt.ion()
plt.show()
plt.grid(b=True)
plt.ylim([-1,1])
plt.xlim([data.time[0], data.time[-1]])

line1, = plt.plot([])

# Configure labels for axes
ax = plt.gca()
ax.xaxis.set_major_formatter(FuncFormatter(data.get_xaxis_fmt))
ax.yaxis.set_major_formatter(FuncFormatter(data.get_yaxis_fmt))
ax.fmt_xdata = data.get_xcoord_fmt
ax.fmt_ydata = data.get_ycoord_fmt

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

# Update the plot
line1.set_ydata(data.ch2)
line1.set_xdata(data.time)
plt.pause(0.001)

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

Was this article helpful?

Yes
No

Related Articles

  • Python Spectrum analyzer 'Max hold' function
  • Python: Lock-in Amplifier
  • Python: Laser Lock Box
  • Python: Data Logger (basic)

Sitemap

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

Offices

United States
+1 (619) 332-6230
740 Lomas Santa Fe Dr
Suite 102
Solana Beach, CA 92075

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

Follow us

Youtube LinkedIn

官方微信

Contact us
© 2021 Liquid Instruments. All rights reserved.

Definition by Author

0
0
Expand