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

Python: Phasemeter (streaming)

Written by Paul Cracknell

Updated at December 22nd, 2020

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

Example Python script to implement the Phasemeter (streaming).

# pymoku example: Phasemeter networking streaming
#
# This example starts a 10-second network stream of Channel 1 Phasemeter data
# and processes it live. The contents of each data sample are printed out,
# along with the signal amplitude which may be calculated as A = (I^2 + Q^2).
# 
# (c) 2019 Liquid Instruments Pty. Ltd.
#

from pymoku import Moku, StreamException, FrameTimeout
from pymoku.instruments import Phasemeter
import math

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

try:
 i = m.deploy_or_connect(Phasemeter)

 # Set the measurement rate to ~120Hz
 i.set_samplerate('fast')

 # Automatically acquire a PLL seed frequency for both channels
 i.auto_acquire()

 # Stop previous network session, if any
 i.stop_stream_data()

 # Start a new Phasemeter network stream
 # Channel 1 enabled, Duration 10 seconds
 i.start_stream_data(duration=10, ch1=True, ch2=False)

 # This loop continuously retrieves Phasemeter Channel 1 data samples off
 # the network and prints out their contents. It breaks out of the loop when
 # there are no samples received, indicating the end of the streaming
 # session.
 while True:
 # Get 10 samples off the network at a time
 samples = i.get_stream_data(n=10)

 # No samples indicates end of stream
 if not any(samples):
 break

 # Process the received samples
 # Here we just print the contents of Channel 1 samples
 # Along with signal amplitude (I^2 + Q^2)
 ch1_samples = samples[0]
 for s in ch1_samples:
 # s is of the form [fs, f, count, phase, I, Q]
 print("Ch1 - fs: %f, f: %f, phase: %f, amplitude: %f"
 % (s[0], s[1], s[3], math.sqrt(s[4]**2 + s[5]**2)))

 i.stop_stream_data()
except StreamException as e:
 print("Error occured: %s" % e)
except FrameTimeout:
 print("Logging session timed out")
finally:
 # Close the connection to the Moku:Lab
 m.close()
moku:lab

Was this article helpful?

Yes
No

Related Articles

  • Python: IIR Filter Box (basic)
  • Python: Oscilloscope
  • Python: Phasemeter (plotting)
  • Python: Oscilloscope (plotting)

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