In [1]:
""" setup """
%load_ext autoreload
%autoreload 2

import numpy as np

import matplotlib
matplotlib.use('nbagg')
import matplotlib.pyplot as plt
plt.style.use(['classic'])

from redbaron import redbaron
redbaron.ipython_behavior = False

from pyha.simulation.simulation_interface import assert_sim_match

from scipy import signal
from scipy.interpolate import interp1d
from pyhacores.under_construction.clock_recovery.simple_gardner.gardner import SimpleGardnerTimingRecovery

In [18]:
from pyhacores.under_construction.clock_recovery.test_ import data_gen

insig = data_gen('aaaa123456789abcdefaa', sps=4, fract_delay=0.0)

plt.stem(insig)
plt.show()



In [51]:
sps = 8
insig = data_gen('aaaaaa123456789abcdefaa', sps, int_delay=0, fract_delay=0.4)
recover = SimpleGardnerTimingRecovery(sps)

ret, err, mu = recover.model_main(insig)
plt.plot(ret, label='ret')
plt.plot(err, label='err')
plt.plot(mu, label='mu')
#     plt.plot(sig_f[::sps], label='decimated input')
plt.grid()
plt.legend()
plt.show()

bits = [1 if x >0 else 0 for x in ret]
print(bits)
from pyha.common.util import bools_to_hex
print(bools_to_hex(bits[0:]))


[1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0]
0xaaaaaa123456789abcdefaa

In [29]:
sps = 4
insig = data_gen('aaaaaa123456789abcdefaa', sps, int_delay=4, fract_delay=0.292, noise_amp=0.2)
recover = SimpleGardnerTimingRecovery(sps)

ret, err, mu = recover.model_main(insig)
plt.plot(ret, label='ret')
plt.plot(err, label='err')
plt.plot(mu, label='mu')
#     plt.plot(sig_f[::sps], label='decimated input')
plt.grid()
plt.legend()
plt.show()

bits = [1 if x >0 else 0 for x in ret]
print(bits)
from pyha.common.util import bools_to_hex
print(bools_to_hex(bits[0:]))


[0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0]
0x2aaaaa123456789abcdefaa

In [ ]: