Skip to content

Instantly share code, notes, and snippets.

@nbecker
Created Mar 8, 2022
Embed
What would you like to do?
crl.py
from transonic import boost
import numpy as np
@boost
class crl:
k: float
aT: float
sum1: float
sum2: float
def __init__ (self, omega_n, zeta, init=0):
self.k = 2 * zeta * omega_n
self.aT = omega_n / (2 * zeta)
self.sum1 = 0
self.sum2 = init
@boost
def call1 (self, xmit: complex, rcv: complex):
mix_out = rcv * np.exp (-1j * self.sum2)
err = np.angle (mix_out * xmit.conj())
freq = self.k * (self.aT * self.sum1 + err)
self.sum1 += err
self.sum2 += freq
return mix_out
@boost
def __call__ (self, xmit: 'complex[]', rcv: 'complex[]'):
if len (xmit) != len (rcv):
raise RuntimeError ('loop_2nd: size mismatch')
out = np.empty (len (xmit), dtype=rcv.dtype)
phase = np.empty (len (xmit))
freq = np.empty (len (xmit))
for i, (x,r) in enumerate (zip (xmit, rcv)):
phase[i] = self.sum2
freq[i] = self.sum1
out[i] = self.call1 (x, r)
return out, phase, freq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment