bag.data.ltv
This module defines functions and classes for linear time-varying circuits data post-processing.
Module Contents
Classes
A class that computes finite impulse response of a linear time-varying circuit. |
Functions
|
Returns a / b if it is an integer, -1 if it is not.. |
- bag.data.ltv._even_quotient(a, b, tol=1e-06)[source]
Returns a / b if it is an integer, -1 if it is not..
- class bag.data.ltv.LTVImpulseFinite(hmat, m, n, tper, k, out0)[source]
Bases:
object
A class that computes finite impulse response of a linear time-varying circuit.
This class computes the time-varying impulse response based on PSS/PAC simulation data, and provides several useful query methods. Your simulation should be set up as follows:
Setup PSS as usual. We will denote system period as tper and fc = 1/tper.
In PAC, set the maxmimum sidebands to m.
In PAC, set the input frequency sweep to be absolute, and sweep from 0 to n * fstep in steps of fstep, where fstep = fc / k for some integer k.
k should be chosen so that the output settles back to 0 after time k * tper. k should also be chosen such that fstep is a nice round frequency. Otherwise, numerical errors may introduce strange results.
n should be chosen so that n * fstep is sufficiently large compared to system bandwidth.
In PAC options, set the freqaxis option to be “in”.
After simulation, PAC should save the output frequency response as a function of output harmonic number and input frequency. Post-process this into a complex 2D matrix hmat with shape (2 * m + 1, n + 1), and pass it to this class’s constructor.
- Parameters:
hmat (np.ndarray) – the PAC simulation data matrix with shape (2 * m + 1, n + 1). hmat[a + m, b] is the complex AC gain from input frequency b * fc / k to output frequency a * fc + b * fc / k.
m (int) – number of output sidebands.
n (int) – number of input frequencies.
tper (float) – the system period, in seconds.
k (int) – the ratio between period of the input impulse train and the system period. Must be an integer.
out0 (
numpy.ndarray
) – steady-state output transient waveform with 0 input over 1 period. This should be a two-column array, where the first column is time vector and second column is the output. Used to compute transient response.
Notes
This class uses the algorithm described in [1] to compute impulse response from PSS/PAC simulation data. The impulse response \(h(t, \tau)\) satisfies the following equation:
\[y(t) = \int_{-\infty}^{\infty} h(t, \tau) \cdot x(\tau)\ d\tau\]Intuitively, \(h(t, \tau)\) represents the output at time \(t\) subject to an impulse at time \(\tau\). As described in the paper, If \(w_c\) is the system frequency, and \(H_m(jw)\) is the frequency response of the system at \(mw_c + w\) due to an input sinusoid with frequency \(w\), then the impulse response can be calculated as:
\[h(t, \tau) = \frac{1}{kT}\sum_{n=-\infty}^{\infty}\sum_{m=-\infty}^{\infty} H_m\left (j\dfrac{nw_c}{k}\right) \exp \left[ jmw_ct + j\dfrac{nw_c}{k} (t - \tau)\right]\]where \(0 \le \tau < T\) and \(\tau \le t \le \tau + kT\).
References
- __call__(t, tau, debug=False)[source]
Calculate h(t, tau).
Compute h(t, tau), which is the output at t subject to an impulse at time tau. standard numpy broadcasting rules apply.
- Parameters:
t (array-like) – the output time.
tau (array-like) – the input impulse time.
debug (bool) – True to print debug messages.
- Returns:
val – the time-varying impulse response evaluated at the given coordinates.
- Return type:
numpy.ndarray
- _get_core(num_points, debug=False)[source]
Returns h(dt, tau) matrix and output waveform over 1 period. Used by lsim.
Compute h(dt, tau) for 0 <= tau < T and 0 <= dt < kT, where dt = t - tau.
- visualize(fig_idx, num_points, num_period=None, plot_color=True, plot_3d=False, show=True)[source]
Visualize the time-varying impulse response.
- Parameters:
fig_idx (int) – starting figure index.
num_points (int) – number of sample points in a period.
num_period (int) – number of output period.
plot_color (bool) – True to create a plot of the time-varying impulse response as 2D color plot.
plot_3d (bool) – True to create a 3D plot of the impulse response.
show (bool) – True to show the plots immediately. Set to False if you want to create some other plots.
- lsim(u, tstep, tstart=0.0, ac_only=False, periodic=False, debug=False)[source]
Compute the output waveform given input waveform.
This method assumes zero initial state. The output waveform will be the same length as the input waveform, so pad zeros if necessary.
- Parameters:
u (array-like) – the input waveform.
tstep (float) – the input/output time step, in seconds. Must evenly divide system period.
tstart (float) – the time corresponding to u[0]. Assume u = 0 for all time before tstart. Defaults to 0.
ac_only (bool) – Return output waveform due to AC input only and without steady-state transient.
periodic (bool) – True if the input is periodic. If so, returns steady state output.
debug (bool) – True to print debug messages.
- Returns:
y – the output waveform.
- Return type:
numpy.ndarray
Notes
This method computes the integral:
\[y(t) = \int_{-\infty}^{\infty} h(t, \tau) \cdot x(\tau)\ d\tau\]using the following algorithm:
set \(d\tau = \texttt{tstep}\).
Compute \(h(\tau + dt, \tau)\) for \(0 \le dt < kT\) and \(0 \le \tau < T\), then express as a kN-by-N matrix. This matrix completely describes the time-varying impulse response.
tile the impulse response matrix horizontally until its number of columns matches input signal length, then multiply column i by u[i].
Compute y as the sum of all anti-diagonals of the matrix computed in previous step, multiplied by \(d\tau\). Truncate if necessary.
- lsim_digital(tsym, tstep, data, pulse, tstart=0.0, nchain=1, tdelta=0.0, **kwargs)[source]
Compute output waveform given input pulse shape and data.
This method is similar to
lsim()
, but assumes the input is superposition of shifted and scaled copies of a given pulse waveform. This assumption speeds up the computation and is useful for high speed link design.- Parameters:
tsym (float) – the symbol period, in seconds. Must evenly divide system period.
tstep (float) – the output time step, in seconds. Must evenly divide symbol period.
pulse (np.ndarray) – the pulse waveform as a two-column array. The first column is time, second column is pulse waveform value. Linear interpolation will be used if necessary. Time must start at 0.0 and be increasing.
tstart (float) – time of the first data symbol. Defaults to 0.0
nchain (int) – number of blocks in a chain. Defaults to 1. This argument is useful if you have multiple blocks cascaded together in a chain, and you wish to find the output waveform at the end of the chain.
tdelta (float) – time difference between adjacent elements in a chain. Defaults to 0. This argument is useful for simulating a chain of latches, where blocks operate on alternate phases of the clock.
kwargs (dict[str, any]) – additional keyword arguments for
lsim()
.
- Returns:
output – the output waveform over N symbol period, where N is the given data length.
- Return type:
numpy.ndarray