Filters

This example shows the basics of working with filter modules. We'll expand on the gain stage we built in the Hello World example.

import zrna
z = zrna.api.Client()
z.connect()
z.clear()

# Declare IO as before
audio_in = z.AudioIn()
audio_out = z.AudioOut()
z.add(audio_in)
z.add(audio_out)

# This time we'll work with a lowpass
# filter instead of a gain module

# 1st order lowpass
lpf = z.FilterLowpass()
z.add(lpf)

# Let's check what parameters it has
print(lpf.parameters) # ['corner_frequency', 'gain']

# We'll leave the gain at unity
# and sweep the corner frequency

# Check range
print(lpf.corner_frequency.minimum) # 4.0
print(lpf.corner_frequency.maximum) # 400.0

# By default the corner frequency
# can vary from 4 kHz to 400 kHz

# We're working with an audio signal so
# let's move this range down by adjusting
# the module clock divisor
lpf.set_clock(z.CLOCK3)

# Check the range again
print(lpf.corner_frequency.minimum) # 0.25
print(lpf.corner_frequency.maximum) # 25.0

# Great now we can sweep from 250 Hz to 25 kHz

# Let's wire up our modules
audio_in.output.connect(lpf.input)
lpf.output.connect(audio_out.input)

# Set the corner frequency to the minimum value
lpf.corner_frequency = 0.25

# Set the circuit in motion
z.run()

# Log sweep from 250 Hz to 25 kHz over 10 seconds
import numpy
import math
import time

f_low = 0.25
f_high = 20.0
steps = 1000

while True:
    for f in numpy.logspace(math.log(f_low, 10),
                            math.log(f_high, 10),
                            steps):
        lpf.corner_frequency = f
        time.sleep(0.01)

Privacy

© 2019 Zrna Research