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: IIR Filter Box (plotting)

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 IIR Filter Box (plotting)

# pymoku example: Plotting IIR Filter Box
#
# This example demonstrates how you can configure the IIR Filter instrument,
# configure real-time monitoring of the input and output signals.
# 
# (c) 2019 Liquid Instruments Pty. Ltd.
# 

from pymoku import Moku
from pymoku.instruments import IIRFilterBox

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

# This script provides a basic example showing how to load coefficients from an
# array into the IIRFilterBox and how to set up oscilloscope probes to monitor
# time domain signals at different points in the instrument.

# The following example array produces an 8th order Direct-form 1 Chebyshev
# type 2 IIR filter with a normalized stopband frequency of 0.2 pi rad/sample
# and a stopband attenuation of 40 dB. Output gain is set to 1.0. See the
# IIRFilterBox documentation for array dimension specifics.
filt_coeff = [
 [
 1.0000000000
 ], [
 1.0000000000, 0.6413900006, -1.0290561741,
 0.6413900006, -1.6378425857, 0.8915664128
 ], [
 1.0000000000, 0.5106751138, -0.7507394931,
 0.5106751138, -1.4000444473, 0.6706551819
 ], [
 1.0000000000, 0.3173108134, -0.3111365531,
 0.3173108134, -1.0873085012, 0.4107935750
 ], [
 1.0000000000, 0.1301131088, 0.1223154629,
 0.1301131088, -0.7955572476, 0.1780989281
 ]
]

m = Moku.get_by_name('Moku')

try:
 i = m.deploy_or_connect(IIRFilterBox)

 i.set_frontend(1, fiftyr=True, atten=False, ac=False)
 i.set_frontend(2, fiftyr=True, atten=False, ac=False)

 # Both filters have the same coefficients, but the different sampling rates
 # mean the resultant transfer functions will be different by a factor of
 # 128 (the ratio of sampling rates)
 i.set_filter(1, sample_rate='high', filter_coefficients=filt_coeff)
 i.set_filter(2, sample_rate='low', filter_coefficients=filt_coeff)

 # Filter channel 1 acts solely on the data from ADC CH1. Filter channel 2
 # acts solely on ADC CH 2.
 i.set_control_matrix(1, scale_in1=1.0, scale_in2=0.0)
 i.set_control_matrix(2, scale_in1=0.0, scale_in2=1.0)

 # Set up monitoring on the input and output of the first filter channel.
 i.set_monitor('a', 'in1')
 i.set_monitor('b', 'out1')

 # Trigger on monitor channel 'a', rising edge, 0V with 0.1V hysteresis
 i.set_trigger('a', 'rising', 0)

 # View +/- 1 microsecond with the trigger point centered
 i.set_timebase(-1e-3, 1e-3)

 # Get initial data frame to set up plotting parameters.
 data = i.get_realtime_data()

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

 line1, = plt.plot([])
 line2, = 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.ch1)
 line2.set_ydata(data.ch2)
 line1.set_xdata(data.time)
 line2.set_xdata(data.time)
 plt.pause(0.001)

finally:
 m.close()
moku:lab

Was this article helpful?

Yes
No

Related Articles

  • Python Spectrum analyzer 'Max hold' function
  • Python: Data Logger (basic)
  • Python: IIR Filter Box (basic)
  • Python: Data Logger (streaming)

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