Created
April 1, 2025 05:34
-
-
Save kumanna/23ca495c2115402fc52aac03931b634a to your computer and use it in GitHub Desktop.
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 | |
import matplotlib.pyplot as plt | |
Ts = 0.0001 | |
fs = 1 / Ts | |
t = np.arange(0, 1, Ts) | |
V_pi = 5 | |
V_bias = 2.5 | |
f_dither = 1000 | |
def get_fft_val(V_bias_base, V_bias_dither_amp, N=4096): | |
V_bias_dither = V_bias_base + V_bias_dither_amp * np.cos(2 * np.pi * f_dither * t) | |
x = 0.5 * (1 + np.cos(np.pi * V_bias_dither / V_pi)) | |
# Photodetector gets only the magnitude plus dc part | |
y = np.abs(x) | |
y = y - np.mean(y) | |
Y = np.fft.fft(y[:N]) | |
return Y, y | |
N = 4096 | |
for V_bias_vals in [1.5, 2.0, 2.5, 2.75, 3, 3.5, 4]: | |
Y, y = get_fft_val(V_bias_vals, 2.5, N) | |
f_vals = np.arange(N) * fs / N | |
f_vals[N//2:] -= fs | |
plt.plot(np.fft.fftshift(f_vals), np.fft.fftshift(20*np.log10(np.abs(Y))), label=str(V_bias_vals)) | |
v = plt.axis() | |
print(f"{V_bias_vals}: {10*np.log10(np.abs(np.trapz(y * np.exp(1j * 2 * np.pi * 2 * f_dither * t), t)))}") | |
plt.legend() | |
plt.axis([v[0], v[1], -80, v[3]]) | |
plt.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment