Loading a Hadamard Ramp Simulation

Builds on…

 7 import cbadc
 8 import cbadc.datasets.hadamard
 9 import scipy.signal
10 import numpy as np
11 import matplotlib.pyplot as plt

Create a Simulation Wrapper

We load the PCB A prototype by instantiating the wrapper class as

20 simulation_wrapper = cbadc.datasets.hadamard.HadamardPCB('B')

Load a specific simulation

In this case we load cbadc.datasets.hadamard.HadamardPCB.simulation_ramp_1_B() simulation by invoking

30 control_signal, ideal_control_signal, simulator, size = simulation_wrapper.simulation_ramp_1_B()
31
32 size = 1 << 12

Configure a Digital Estimator

37 eta2 = 1e5
38 L1 = 1 << 10
39 L2 = 1 << 10
40 OSR = 1 << 5
41
42
43 digital_estimator = cbadc.digital_estimator.FIRFilter(
44     simulator.analog_system,
45     simulator.digital_control,
46     eta2,
47     L1,
48     L2,
49     downsample=OSR)
50
51 print(digital_estimator, "\n")
52
53 digital_estimator(control_signal)

Out:

FIR estimator is parameterized as
eta2 = 100000.00, 50 [dB],
Ts = 1e-06,
K1 = 1024,
K2 = 1024,
and
number_of_iterations = 9223372036854775808.
Resulting in the filter coefficients
h =
[[[-1.78705424e-11  3.59873868e-12  6.75066574e-13 ...  5.09395743e-12
    3.63212138e-12  5.64068310e-12]
  [-1.85063565e-11  3.47173121e-12  7.55741807e-13 ...  5.19952008e-12
    3.84152538e-12  5.78952380e-12]
  [-1.91180522e-11  3.33009324e-12  8.37677092e-13 ...  5.29530790e-12
    4.04909983e-12  5.92876483e-12]
  ...
  [-1.91180522e-11 -3.33009324e-12  8.37677092e-13 ...  3.84487966e-12
    5.92876483e-12  4.04909983e-12]
  [-1.85063565e-11 -3.47173121e-12  7.55741807e-13 ...  3.67578729e-12
    5.78952380e-12  3.84152538e-12]
  [-1.78705424e-11 -3.59873868e-12  6.75066574e-13 ...  3.50378048e-12
    5.64068310e-12  3.63212138e-12]]].

Post filtering with FIR

60 numtaps = 1 << 10
61 f_cutoff = 1.0 / OSR
62 fir_filter = scipy.signal.firwin(numtaps, f_cutoff)
63
64 digital_estimator.convolve((fir_filter))

Filtering Estimate

71 u_hat = np.zeros(size // OSR)
72 for index in cbadc.utilities.show_status(range(size // OSR)):
73     u_hat[index] = next(digital_estimator)

Out:

  0%|          | 0/128 [00:00<?, ?it/s]
  1%|          | 1/128 [00:00<01:06,  1.91it/s]
 76%|#######5  | 97/128 [00:00<00:00, 207.19it/s]
100%|##########| 128/128 [00:00<00:00, 194.49it/s]

Visualize Estimate

80 t = np.arange(size // OSR) * OSR
81 plt.plot(t, u_hat, label="$\hat{u}(t)$")
82 plt.xlabel('$t / T$')
83 plt.legend()
84 plt.title("Estimated input signal")
85 plt.grid(which='both')
86 # offset = (L1 + L2) * 4
87 # plt.xlim((offset, offset + 1000))
88 plt.ylim((-0.6, 0.6))
89 plt.tight_layout()
Estimated input signal

Visualize Estimate Spectrum

 96 plt.figure()
 97 u_hat_clipped = u_hat[(L1 + L2) // OSR:]
 98 freq, psd = cbadc.utilities.compute_power_spectral_density(
 99     u_hat_clipped, fs=1.0/(simulator.digital_control.T * OSR))
100 plt.semilogx(freq, 10 * np.log10(psd), label="$\hat{U}(f)$")
101 plt.legend()
102 plt.ylim((-300, 50))
103 # plt.xlim((f_ref[1], f_ref[-1]))
104 plt.xlabel('$f$ [Hz]')
105 plt.ylabel('$ \mathrm{V}^2 \, / \, (1 \mathrm{Hz})$')
106 plt.grid(which='both')
107 plt.show()
plot hadamard

Out:

/home/hammal/anaconda3/envs/py38/lib/python3.8/site-packages/scipy/signal/spectral.py:1964: UserWarning: nperseg = 16384 is greater than input length  = 64, using nperseg = 64
  warnings.warn('nperseg = {0:d} is greater than input length '

Total running time of the script: ( 0 minutes 9.377 seconds)

Gallery generated by Sphinx-Gallery