Modules in pybert package¶
pybert - Main PyBERT class definition, as well as some helper classes.¶
Bit error rate tester (BERT) simulator, written in Python.
Original Author: David Banas <capn.freako@gmail.com>
Original Date: 17 June 2014
Testing by: Mark Marlett <mark.marlett@gmail.com>
This Python script provides a GUI interface to a BERT simulator, which can be used to explore the concepts of serial communication link design.
Copyright (c) 2014 by David Banas; All rights reserved World wide.
-
class
pybert.pybert.
PyBERT
(run_simulation=True)[source]¶ A serial communication link bit error rate tester (BERT) simulator with a GUI interface.
Useful for exploring the concepts of serial communication link design.
Initial plot setup occurs here.
In order to populate the data structure we need to construct the plots, we must run the simulation.
Parameters: run_simulation (Bool) – If true, run the simulation, as part of class initialization. This is provided as an argument for the sake of larger applications, which may be importing PyBERT for its attributes and methods, and may not want to run the full simulation. (Optional; default = True) -
calc_chnl_h
()[source]¶ Calculates the channel impulse response.
- Also sets, in ‘self’:
- chnl_dly:
group delay of channel
- start_ix:
first element of trimmed response
- t_ns_chnl:
the x-values, in ns, for plotting ‘chnl_h’
- chnl_H:
channel frequency response
- chnl_s:
channel step response
- chnl_p:
channel pulse response
-
-
class
pybert.pybert.
TxOptThread
(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]¶ Used to run Tx tap weight optimization in its own thread, in order to preserve GUI responsiveness.
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
class
pybert.pybert.
RxOptThread
(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]¶ Used to run Rx tap weight optimization in its own thread, in order to preserve GUI responsiveness.
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
-
class
pybert.pybert.
CoOptThread
(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]¶ Used to run co-optimization in its own thread, in order to preserve GUI responsiveness.
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
pybert_cntrl - Model control logic.¶
Default controller definition for PyBERT class.
Original author: David Banas <capn.freako@gmail.com>
Original date: August 24, 2014 (Copied from `pybert.py’, as part of a major code cleanup.)
Copyright (c) 2014 David Banas; all rights reserved World wide.
-
pybert.pybert_cntrl.
my_run_sweeps
(self)[source]¶ Runs the simulation sweeps.
Parameters: self (PyBERT) – Reference to an instance of the PyBERT class.
-
pybert.pybert_cntrl.
my_run_simulation
(self, initial_run=False, update_plots=True)[source]¶ Runs the simulation.
Parameters: - self (PyBERT) – Reference to an instance of the PyBERT class.
- initial_run (Bool) – If True, don’t update the eye diagrams, since they haven’t been created, yet. (Optional; default = False.)
- update_plots (Bool) – If True, update the plots, after simulation completes. This option can be used by larger scripts, which import pybert, in order to avoid graphical back-end conflicts and speed up this function’s execution time. (Optional; default = True.)
pybert_view - Main GUI window layout definition.¶
Default view definition for PyBERT class.
Original author: David Banas <capn.freako@gmail.com>
Original date: August 24, 2014 (Copied from `pybert.py’, as part of a major code cleanup.)
Copyright (c) 2014 David Banas; all rights reserved World wide.
-
class
pybert.pybert_view.
MyHandler
[source]¶ This handler is instantiated by the View and handles user button clicks.
-
class
pybert.pybert_view.
RunSimThread
(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)[source]¶ Used to run the simulation in its own thread, in order to preserve GUI responsiveness.
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is the argument tuple for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
pybert_util - Various utilities used by other modules.¶
General purpose utilities for PyBERT.
Original author: David Banas <capn.freako@gmail.com>
Original date: September 27, 2014 (Copied from `pybert_cntrl.py’.)
Copyright (c) 2014 David Banas; all rights reserved World wide.
-
pybert.pybert_util.
moving_average
(a, n=3)[source]¶ Calculates a sliding average over the input vector.
Parameters: - a ([float]) – Input vector to be averaged.
- n (int) – Width of averaging window, in vector samples. (Optional; default = 3.)
- Returns: the moving average of the input vector, leaving the input
- vector unchanged.
-
pybert.pybert_util.
find_crossing_times
(t, x, min_delay=0.0, rising_first=True, min_init_dev=0.1, thresh=0.0)[source]¶ Finds the threshold crossing times of the input signal.
Parameters: - t ([float]) – Vector of sample times. Intervals do NOT need to be uniform.
- x ([float]) – Sampled input vector.
- min_delay (float) – Minimum delay required, before allowing crossings. (Helps avoid false crossings at beginning of signal.) (Optional; default = 0.)
- rising_first (bool) – When True, start with the first rising edge found. (Optional; default = True.) When this option is True, the first rising edge crossing is the first crossing returned. This is the desired behavior for PyBERT, because we always initialize the bit stream with [0, 0, 1, 1], in order to provide a known synchronization point for jitter analysis.
- min_init_dev (float) – The minimum initial deviation from zero, which must be detected, before searching for crossings. Normalized to maximum input signal magnitude. (Optional; default = 0.1.)
- thresh (float) – Vertical crossing threshold.
Returns: an array of signal threshold crossing times.
-
pybert.pybert_util.
find_crossings
(t, x, amplitude, min_delay=0.0, rising_first=True, min_init_dev=0.1, mod_type=0)[source]¶ Finds the crossing times in a signal, according to the modulation type.
Parameters: - t ([float]) – The times associated with each signal sample.
- x ([float]) – The signal samples.
- amplitude (float) – The nominal signal amplitude. (Used for determining thresholds, in the case of some modulation types.)
- min_delay (float) – The earliest possible sample time we want returned. (Optional; default = 0.)
- rising_first (bool) – When True, start with the first rising edge found. When this option is True, the first rising edge crossing is the first crossing returned. This is the desired behavior for PyBERT, because we always initialize the bit stream with [0, 1, 1], in order to provide a known synchronization point for jitter analysis. (Optional; default = True.)
- min_init_dev (float) – The minimum initial deviation from zero, which must be detected, before searching for crossings. Normalized to maximum input signal magnitude. (Optional; default = 0.1.)
- mod_type (int) – The modulation type. Allowed values are: {0: NRZ, 1: Duo-binary, 2: PAM-4} (Optional; default = 0.)
Returns: The signal threshold crossing times.
-
pybert.pybert_util.
calc_jitter
(ui, nui, pattern_len, ideal_xings, actual_xings, rel_thresh=6, num_bins=99, zero_mean=True)[source]¶ Calculate the jitter in a set of actual zero crossings, given the ideal crossings and unit interval.
Inputs:
- ui : The nominal unit interval.
- nui : The number of unit intervals spanned by the input signal.
- pattern_len : The number of unit intervals, before input symbol stream repeats.
- ideal_xings : The ideal zero crossing locations of the edges.
- actual_xings : The actual zero crossing locations of the edges.
- rel_thresh : (optional) The threshold for determining periodic jitter spectral components (sigma).
- num_bins : (optional) The number of bins to use, when forming histograms.
- zero_mean : (optional) Force the mean jitter to zero, when True.
Outputs:
- jitter : The total jitter.
- t_jitter : The times (taken from ‘ideal_xings’) corresponding to the returned jitter values.
- isi : The peak to peak jitter due to intersymbol interference.
- dcd : The peak to peak jitter due to duty cycle distortion.
- pj : The peak to peak jitter due to uncorrelated periodic sources.
- rj : The standard deviation of the jitter due to uncorrelated unbounded random sources.
- tie_ind : The data independent jitter.
- thresh : Threshold for determining periodic components.
- jitter_spectrum : The spectral magnitude of the total jitter.
- tie_ind_spectrum : The spectral magnitude of the data independent jitter.
- spectrum_freqs : The frequencies corresponding to the spectrum components.
- hist : The histogram of the actual jitter.
- hist_synth : The histogram of the extrapolated jitter.
- bin_centers : The bin center values for both histograms.
-
pybert.pybert_util.
make_uniform
(t, jitter, ui, nbits)[source]¶ Make the jitter vector uniformly sampled in time, by zero-filling where necessary.
The trick, here, is creating a uniformly sampled input vector for the FFT operation, since the jitter samples are almost certainly not uniformly sampled. We do this by simply zero padding the missing samples.
Inputs:
- t : The sample times for the ‘jitter’ vector.
- jitter : The input jitter samples.
- ui : The nominal unit interval.
- nbits : The desired number of unit intervals, in the time domain.
Output:
- y : The uniformly sampled, zero padded jitter vector.
- y_ix : The indices where y is valid (i.e. - not zero padded).
-
pybert.pybert_util.
calc_gamma
(R0, w0, Rdc, Z0, v0, Theta0, ws)[source]¶ Calculates propagation constant from cross-sectional parameters.
The formula’s applied are taken from Howard Johnson’s “Metallic Transmission Model” (See “High Speed Signal Propagation”, Sec. 3.1.)
- Inputs:
- R0 skin effect resistance (Ohms/m)
- w0 cross-over freq.
- Rdc d.c. resistance (Ohms/m)
- Z0 characteristic impedance in LC region (Ohms)
- v0 propagation velocity (m/s)
- Theta0 loss tangent
- ws frequency sample points vector
- Outputs:
- gamma frequency dependent propagation constant
- Zc frequency dependent characteristic impedance
-
pybert.pybert_util.
calc_G
(H, Rs, Cs, Zc, RL, Cp, CL, ws)[source]¶ Calculates fully loaded transfer function of complete channel.
- Inputs:
- H unloaded transfer function of interconnect
- Rs source series resistance
- Cs source parallel (parasitic) capacitance
- Zc frequency dependent characteristic impedance of the interconnect
- RL load resistance (differential)
- Cp load parallel (parasitic) capacitance (single ended)
- CL load series (d.c. blocking) capacitance (single ended)
- ws frequency sample points vector
- Outputs:
- G frequency dependent transfer function of channel
-
pybert.pybert_util.
calc_eye
(ui, samps_per_ui, height, ys, y_max, clock_times=None)[source]¶ Calculates the “eye” diagram of the input signal vector.
Parameters: - ui (float) – unit interval (s)
- samps_per_ui (int) – # of samples per unit interval
- height (int) – height of output image data array
- ys ([float]) – signal vector of interest
- y_max (float) – max. +/- vertical extremity of plot
Keyword Arguments: clock_times ([float]) – (optional) vector of clock times to use for eye centers. If not provided, just use mean zero-crossing and assume constant UI and no phase jumps. (This allows the same function to be used for eye diagram creation, for both pre and post-CDR signals.)
- Returns: The “heat map” representing the eye diagram. Each grid
- location contains a value indicating the number of times the signal passed through that location.
-
pybert.pybert_util.
make_ctle
(rx_bw, peak_freq, peak_mag, w, mode='Passive', dc_offset=0)[source]¶ Generate the frequency response of a continuous time linear equalizer (CTLE), given the:
- signal path bandwidth,
- peaking specification
- list of frequencies of interest, and
- operational mode/offset.
We use the ‘invres()’ function from scipy.signal, as it suggests itself as a natural approach, given our chosen use model of having the user provide the peaking frequency and degree of peaking.
That is, we define our desired frequency response using one zero and two poles, where:
- The pole locations are equal to:
- the signal path natural bandwidth, and
- the user specified peaking frequency.
The zero location is chosen, so as to provide the desired degree of peaking.
Inputs:
rx_bw The natural (or, unequalized) signal path bandwidth (Hz).
- peak_freq The location of the desired peak in the frequency
response (Hz).
peak_mag The desired relative magnitude of the peak (dB). (mag(H(0)) = 1)
w The list of frequencies of interest (rads./s).
- mode The operational mode; must be one of:
- ‘Off’ : CTLE is disengaged.
- ‘Passive’: Maximum frequency response has magnitude one.
- ‘AGC’ : Automatic gain control. (Handled by calling routine.)
- ‘Manual’ : D.C. offset is set manually.
- dc_offset The d.c. offset of the CTLE gain curve (dB).
(Only valid, when ‘mode’ = ‘Manual’.)
Outputs:
- w, H The resultant complex frequency response, at the
given frequencies.
-
pybert.pybert_util.
trim_impulse
(g, Ts=0, chnl_dly=0, min_len=0, max_len=1000000)[source]¶ - Trim impulse response, for more useful display, by:
- eliminating 90% of the overall delay from the beginning, and
- clipping off the tail, after 99.8% of the total power has been captured. (Using 99.9% was causing problems; I don’t know why.)
Inputs:
- g impulse response
- Ts (optional) sample interval (same units as ‘chnl_dly’)
- chnl_dly (optional) channel delay
- min_len (optional) minimum length of returned vector
- max_len (optional) maximum length of returned vector
Outputs:
- g_trim trimmed impulse response
- start_ix index of first returned sample
pybert_plot - Plot definitions for the PyBERT GUI.¶
Plot definitions for PyBERT class.
Original author: David Banas <capn.freako@gmail.com>
Original date: February 21, 2015 (Copied from `pybert.py’, as part of a major code cleanup.)
Copyright (c) 2015 David Banas; all rights reserved World wide.
pybert_help - Contents of the Help tab of the PyBERT GUI.¶
User instructions for PyBERT class.
Original author: David Banas <capn.freako@gmail.com>
Original date: April 15, 2015 (Copied from `pybert.py’.)
Copyright (c) 2015 David Banas; all rights reserved World wide.
dfe - DFE behavioral model.¶
Behavioral model of a decision feedback equalizer (DFE).
Original Author: David Banas <capn.freako@gmail.com>
Original Date: 17 June 2014
This Python script provides a behavioral model of a decision feedback equalizer (DFE). The class defined, here, is intended for integration into the larger PyBERT framework.
Copyright (c) 2014 by David Banas; All rights reserved World wide.
-
class
pybert.dfe.
LfilterSS
(b, a)[source]¶ A single steppable version of scipy.signal.lfilter().
Parameters: - b ([float]) – Coefficients of the numerator of the rational transfer function.
- a ([float]) – Coefficients of the denominator of the rational transfer function.
-
class
pybert.dfe.
DFE
(n_taps, gain, delta_t, alpha, ui, n_spb, decision_scaler, mod_type=0, bandwidth=100000000000.0, n_ave=10, n_lock_ave=500, rel_lock_tol=0.01, lock_sustain=500, ideal=True)[source]¶ Behavioral model of a decision feedback equalizer (DFE).
Inputs:
Required:
n_taps # of taps in adaptive filter
gain adaptive filter tap weight correction gain
delta_t CDR proportional branch constant (ps)
alpha CDR integral branch constant (normalized to delta_t)
ui nominal unit interval (ps)
n_spb # of samples per unit interval
- decision_scaler multiplicative constant applied to the result of
the sign function, when making a “1 vs. 0” decision. Sets the target magnitude for the DFE.
Optional:
- mod_type The modulation type:
- 0: NRZ
- 1: Duo-binary
- 2: PAM-4
bandwidth The bandwidth, at the summing node (Hz).
- n_ave The number of averages to take, before adapting.
(Also, the number of CDR adjustments per DFE adaptation.)
- n_lock_ave The number of unit interval estimates to
consider, when determining locked status.
rel_lock_tol The relative tolerance for determining lock.
- lock_sustain Length of the histerysis vector used for
lock flagging.
ideal Boolean flag. When true, use an ideal summing node.
Raises: Exception
– If the requested modulation type is unknown.-
decide
(x)[source]¶ Make the bit decisions, according to modulation type.
Parameters: x (float) – The signal value, at the decision time. Returns: tuple – The members of the returned tuple are: - decision:
- One of:
- {-1, 1} (NRZ)
- {-1, 0, +1} (Duo-binary)
- {-1, -1/3, +1/3, +1} (PAM-4)
according to what the ideal signal level should have been. (‘decision_scaler’ normalized)
bits: The list of bits recovered.
Return type: float, [int] Raises: Exception
– If the requested modulation type is unknown.
-
run
(sample_times, signal)[source]¶ Run the DFE on the input signal.
Parameters: - sample_times ([float]) – Vector of time values at wich corresponding signal values were sampled.
- signal ([float]) – Vector of sampled signal values.
Returns: tuple – The members of the returned tuple, in order, are:
- res([float]):
Samples of the summing node output, taken at the times given in sample_times.
- tap_weights([[float]]):
List of list of tap weights showing how the DFE adapted over time.
- ui_ests([float]):
List of unit interval estimates, showing how the CDR adapted.
- clocks([int]):
List of mostly zeros with ones at the recovered clocking instants. Useful for overlaying the clock times on signal waveforms, in plots.
- lockeds([bool]):
List of Booleans indicating state of CDR lock.
- clock_times([float]):
List of clocking instants, as recovered by the CDR.
- bits([int]):
List of recovered bits.
Return type: ([float], [[float]], [float], [int], [bool], [float], [int]
Raises: Exception
– If the requested modulation type is unknown.
-
step
(decision, error, update)[source]¶ Step the DFE, according to the new decision and error inputs.
Parameters: - decision (float) – Current slicer output.
- error (float) – Difference between summing node and slicer outputs.
- update (bool) – If true, update tap weights.
Returns: res – New backward filter output value.
Return type: float
cdr - CDR behavioral model.¶
Behavioral model of a “bang-bang” clock data recovery (CDR) unit.
Original Author: David Banas <capn.freako@gmail.com>
Original Date: 17 June 2014
This Python script provides a behavioral model of a “bang-bang” clock data recovery (CDR) unit. The class defined, here, is intended for integration into the larger PyBERT framework.
Copyright (c) 2014 by David Banas; All rights reserved World wide.
-
class
pybert.cdr.
CDR
(delta_t, alpha, ui, n_lock_ave=500, rel_lock_tol=0.01, lock_sustain=500)[source]¶ A class providing behavioral modeling of a ‘bang- bang’ clock data recovery (CDR) unit.
Parameters: - delta_t (float) – The proportional branch correction, in seconds.
- alpha (float) – The integral branch correction, normalized to proportional branch correction.
- ui (float) – The nominal unit interval, in seconds.
- n_lock_ave (Optional, int) – Number of unit intervals to use for determining lock. Defaults to 500.
- rel_lock_tol (Optional, float) – Lock tolerance, relative to delta_t. Defaults to 0.01.
- lock_sustain (Optional, int) – Length of lock sustain vector used to provide histerysis. Defaults to 500.
Notes
The code does not care what units are actually used for ‘delta_t’ and ‘ui’; only that they are the same.
-
adapt
(samples)[source]¶ Adapt period/phase, according to 3 samples.
Should be called, when the clock has just struck.
- Synopsis:
- (ui, locked) = adapt(samples)
Parameters: samples ([float]) – A list of 3 samples of the input waveform, as follows:
- at the last clock time
- at the last unit interval boundary time
- at the current clock time
Returns: tuple – - ui:
- The new unit interval estimate, in seconds.
- locked:
- Boolean flag indicating ‘locked’ status.
Return type: float, bool
-
locked
¶ The current locked state.
-
ui
¶ The current unit interval estimate.