Skip to content

Commit

Permalink
Added oversampling and sd
Browse files Browse the repository at this point in the history
  • Loading branch information
wulffern committed Feb 8, 2024
1 parent 70090b0 commit 2ce5d48
Show file tree
Hide file tree
Showing 72 changed files with 157,072 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ FILES = l00_diode \
l03_refbias \
l04_afe \
l05_sc \
# l06_adc \
l07_vreg \
l06_adc \
# l07_vreg \
l08_pll \
l09_osc \
l10_lpradio \
Expand Down
Binary file added docs/assets/slides/l06_adc.pdf
Binary file not shown.
34 changes: 24 additions & 10 deletions ex/sd_1st.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import matplotlib.pyplot as plt

#- Create a time vector
N = 2**13
t = np.linspace(0,N,N)

N = 2**12
#t = np.linspace(0,N,N+1)
t = np.arange(0,N)
#- Create the "continuous time" signal
fbin = 10
fbin = 47
fm1 = 1/N*213
f1 = 1/128 - 1/N
#f1 = fbin
fd = fm1
x_s = np.sin(2*np.pi*f1*t) + + 1/2**15*np.random.randn(N)

Expand All @@ -21,17 +22,17 @@
## Sample
#- Sampling frequency is 1/nfs of the time vector
nfs = 4
x_sn = x_s[0::nfs]
u = x_s[0::nfs]

bits = 1
y_sn = np.round(x_sn*2**bits)/2**bits
y_sn = np.round(u*2**bits)/2**bits

dither = 1
M = len(x_sn)
M = len(u)
y_sd = np.zeros(M)
x = np.zeros(M)
for n in range(1,M):
x[n] = x[n-1] + (x_sn[n]-y_sd[n-1])
x[n] = x[n-1] + (u[n]-y_sd[n-1])
y_sd[n] = np.round(x[n]*2**bits + dither*np.random.randn()/4)/2**bits

#- Remove the first samples to get rid of the initial
Expand All @@ -53,7 +54,7 @@ def freqDomain(x):
X = X/np.max(np.abs(X[int(N/4):N-int(N/4)]))
return X
X_s = freqDomain(x_s)
X_sn = freqDomain(x_sn)
u = freqDomain(u)
Y_sn = freqDomain(y_sn)
Y_sdn = freqDomain(y_sd )

Expand All @@ -63,7 +64,7 @@ def freqDomain(x):
plt.ylabel("Frequency Domain")
plt.ylim(-160,0)
plt.subplot(1,4,2)
plt.plot(20*np.log10(np.abs(X_sn)))
plt.plot(20*np.log10(np.abs(u)))
plt.xlabel("Discrete time, continuous value")
plt.ylim(-160,0)
plt.subplot(1,4,3)
Expand All @@ -83,4 +84,17 @@ def freqDomain(x):
fig.set_size_inches(12, 7)
plt.tight_layout()
plt.savefig(f"l6_sd_d{dither}_b{bits}.pdf")


plt.figure()

NN = int(len(Y_sdn)/2)
Y_sdn_short = Y_sdn[NN:]
x_sdn_short = np.arange(0,NN)/NN/2
plt.semilogx(x_sdn_short,20*np.log10(np.abs(Y_sdn[int(len(Y_sdn)/2):])),color="black")
plt.xlabel("Normalized frequency")
plt.ylabel("Magnitude [dB20]")
plt.grid(True)

plt.savefig(f"l6_sdlog_d{dither}_b{bits}.pdf")
plt.show()
Loading

0 comments on commit 2ce5d48

Please sign in to comment.