Created
January 9, 2025 15:19
-
-
Save prydin/e918e543b31bc2363b7d79c6d7cf2e32 to your computer and use it in GitHub Desktop.
Low noise preamp simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
noise_db = -80 # Noise added by each amplifier | |
gain_db = 60 # Closed loop gain | |
cycles = 2 | |
resolution = 1000 | |
length = np.pi * 2 * cycles | |
signal = np.sin(np.arange(0, length, length / resolution)) | |
raw_noise = 10**(noise_db / 20) | |
raw_gain = 10**(gain_db / 20) | |
print("# opamps, simulated noise, theoretical noise") | |
for n_amps in range(1, 10): | |
sum = np.zeros(len(signal)) | |
for _ in range(n_amps): | |
sum += signal * raw_gain + np.random.normal(0, raw_noise, len(signal)) | |
# Total output through the voltage divider | |
output = sum / n_amps | |
# Subtract clean signal to get noise and calculate RMS noise | |
noise_residual = output - signal * raw_gain | |
noise_rms = np.sqrt(np.sum(noise_residual ** 2) / len(signal)) | |
print(n_amps, 20 * np.log10(noise_rms), noise_db - 20 * np.log10(np.sqrt(n_amps))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for doing this much effort. I really appreciate it.