Skip to content

Instantly share code, notes, and snippets.

%Generation of colored noise in Matlab
a=0.9; %low pass filter parameter
Fs=1000; %sampling rate
Fc=10; % carrier frequency for the dummy signal
recordDuration=120; % seconds; a longer record reduces PSD estimation variance
numSamples=round(recordDuration*Fs);
t=(0:numSamples-1)/Fs; %time base
variance = 1; %variance of white noise
@raytroop
raytroop / jitter_pn_closedloop.py
Created August 3, 2026 13:17
oscillator noise verification
#!/usr/bin/env python3
"""
Closed-loop oscillator noise verification
PN targets -> sigma_p^2(N) (table) -> per-period jitter injection
-> edge accumulation -> recomputed PN, plus direct sigma_p(N) check.
Conventions
L(f) = S_phi(f)/2, S_phi one-sided, phase sampled once per period (fs = f0).
Absolute jitter J(n) = t_n - n*T0, phase phi(n) = 2*pi*f0*J(n).
@raytroop
raytroop / alpha_two_level_check.py
Last active July 18, 2026 15:57
ODE verification of injection-locking \Delta\omega_0=0
"""
Neat two-level ODE check of the slide (Dw0 = 0), one eps, one figure (3 panels).
Level 1 (phase ODE, eq.3): da/dt = -B sin(a), B = (E1/E) * w0/(2Q)
Level 2 (raw circuit ODE): C dv/dt + v/R + iL = Ip*sgn(v) + eps*I1*sin(w_osc*t)
L diL/dt = v
Both start at a0 = 90 deg (v0 ~ cos, injection ~ sin) and are compared with
the slide's closed form tan(a/2) = exp(-Bt)*tan(a0/2) and with a0*exp(-Bt).
Two waveform panels show v0(t) right after injection turns on (90 deg ahead
of i_n) and in steady state ((1+eps)*I1*R*sin, in phase with i_n).
@raytroop
raytroop / fit_xcp.py
Last active July 17, 2026 15:30
MOS cross coupled pair w/o current source
#!/usr/bin/env python3
"""
fit_xcp.py -- extract Verilog-A parameters for xcp_nr.va
Model of the swept differential I-V of a MOS cross-coupled pair, including
the triode fold-back and the finite-voltage headroom cutoff:
x = v/vzero, w = max(1 - x^2, 0)
i(v) = -gm0 * v * exp(shape*x^2) * w^2
@raytroop
raytroop / gnr.va
Last active July 13, 2026 13:18
G<sub>eff</sub> - large signal conductance
// -----------------------------------------------------------------------------
// gnr.va
//
// Verilog-A model of the nonlinear active resistor g_nr of Fig. 9.7, plus an
// optional all-Verilog-A testbench of the complete LC oscillator.
//
// The DC characteristic in the inset is an odd, saturating curve:
//
// i(v) = -isat * tanh(v/v0), v0 = isat/g0
// g_nr(v) = di/dv = -g0 * sech^2(v/v0)
"""
Emulation: average output of a phase detector (XOR) vs a phase-frequency
detector (tri-state PFD) when the two inputs differ in frequency.
Setup (open loop, no feedback):
input A = reference square wave at f_a = 1
input B = "VCO" square wave at f_b = f_a - df
Claims demonstrated:
1. XOR PD: time-average -> 0 for every df != 0, identical for +df and -df
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Inductive shunt peaking: bandwidth, peak frequency, and peaking gain
as functions of m = R^2 * C / L.
All frequencies are normalized to 1/RC (i.e. the plotted value is omega * RC).
Smaller m <=> larger inductor L.
Impedance: Z(s)/R = (1 + s L/R) / (1 + s R C + s^2 L C)
With u = (omega * RC)^2 and m = R^2 C / L:
|Z/R|^2 = (1 + u/m^2) / ((1 - u/m)^2 + u)
@raytroop
raytroop / quantization_noise.py
Created June 2, 2026 15:02
computing odd Ap using bessel function
"""
Quantization noise of a sinusoid: harmonic coefficients A_p, noise power,
and the impact of the bit count n.
Model: uniform quantizer, step Delta, input x(t) = A*sin(w t).
The quantization error expands into ODD harmonics only:
e(t) = sum_{p odd} A_p sin(p w t)
For a mid-tread quantizer y = Delta*round(x/Delta) the error e = y - x has
@raytroop
raytroop / q.py
Last active June 2, 2026 14:26
The quantization noise is **odd harmonics of the input signal**
# modified from https://github.com/wulffern/aic2023/blob/main/ex/q.py
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
#- Enable hanning window
hann = True