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 (basic)

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 (basic)

# pymoku example: Basic 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

# This script provides a basic example showing how to load coefficients from an
# array into the IIRFilterBox.

# 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.0
 ], [
 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)

 # Offset filter channel 1 input by 0.1V
 i.set_gains_offsets(1, input_offset=0.1)
 # Filter channel 2 acts on sum of input 1 and 2
 i.set_control_matrix(2, scale_in1=0.5, scale_in2=0.5)

 # Set the monitor timebase to +-1msec
 i.set_timebase(-1e-3, 1e-3)

 # Set up monitoring of the input and output of the second filter channel.
 i.set_monitor('a', 'in2')
 i.set_monitor('b', 'out2')

 # Capture and print one set of time-domain input and output points
 d = i.get_realtime_data()
 print(d.ch1, d.ch2)
finally:
 m.close()
moku:lab

Was this article helpful?

Yes
No

Related Articles

  • Using Python to generate arbitrary waveforms while observing the output signal
  • Python: Frequency Response Analyzer (basic)
  • Python: Frequency Response Analyzer (plotting)
  • 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
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