Skip to content

Instantly share code, notes, and snippets.

"""
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""Plot statistical and empirical eye diagrams from the smoke test fixtures."""
import os
import sys
import matplotlib
# matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
"""
Overlay: OSR=1 (FOH inactive), OSR=16 (FOH active), nd*sinc^2 ideal FOH at
OSR=16, and target nd. noise_gen.va verification.
"""
import numpy as np
import matplotlib
# matplotlib.use("Agg")
import matplotlib.pyplot as plt
%% Complex-conjugate poles of a 2nd-order system vs. quality factor Q
% H(s) ~ 1 / ( s^2 + (w0/Q) s + w0^2 )
% Poles: s = -w0/(2Q) +/- w0*sqrt(1/(4Q^2) - 1)
% For Q > 0.5 the poles are complex conjugates on a circle of radius w0.
clear; clc; close all;
w0 = 1.0; % natural frequency (normalized)
% Discrete Q values to mark with 'x'
clear; clc; close all;
% Parameters
wp = 1; % rad/s
% Frequency axis
w = logspace(-2, 2, 1000);
s = 1j*w;