# 初期の Vin の値と Vref を設定
Vin = 0.2 # 初期の Vin0 の値を適宜変更してください
Vref = 1.0 # Vref の値を適宜変更してください
# Vin1 から VinN までの値を計算する関数
def calculate_vin_values(Vin0, Vref, steps=10):
vin_values = [Vin0] # Vin0 の初期値をリストに追加
D_values = [] # D の値を保存するリスト
for _ in range(steps):
Vin0 = vin_values[-1] # 現在の Vin の値を取得
if Vin0 > 0:
D = 1
Vin_next = 2 * Vin0 - Vref
else:
D = 0
Vin_next = 2 * Vin0 + Vref
vin_values.append(Vin_next)
D_values.append(D)
return vin_values, D_values
# Vin1 から Vin10 までの値を計算
vin_values, D_values = calculate_vin_values(Vin, Vref, steps=10)
# 結果を出力
for i, (vin, D) in enumerate(zip(vin_values, D_values), start=1):
print(f'Step {i}: Vin = {vin_values[i-1]}, D = {D}')
# 初期の Vin の値と Vref を設定
Vin = 0.2 # 初期の Vin0 の値を適宜変更してください
Vref = 1.0 # Vref の値を適宜変更してください
beta = 1.997 # β の値を適宜変更してください
# Vin1 から VinN までの値を計算する関数
def calculate_vin_values(Vin0, Vref, beta, steps=10):
vin_values = [Vin0] # Vin0 の初期値をリストに追加
D_values = [] # D の値を保存するリスト
for _ in range(steps):
Vin0 = vin_values[-1] # 現在の Vin の値を取得
if Vin0 > 0:
D = 1
Vin_next = beta * Vin0 - (beta - 1) * Vref
else:
D = 0
Vin_next = beta * Vin0 + (beta - 1) * Vref
vin_values.append(Vin_next)
D_values.append(D)
return vin_values, D_values
# Vin1 から Vin10 までの値を計算
vin_values, D_values = calculate_vin_values(Vin, Vref, beta, steps=10)
# 結果を出力
for i, (vin, D) in enumerate(zip(vin_values, D_values), start=1):
print(f'Step {i}: Vin = {vin}, D = {D}')
# 最後に D をすべて並べて出力
print("D values:", D_values)
# 初期の Vin の値と Vref を設定
Vin = 0.2001 # 初期の Vin0 の値を適宜変更してください
Vref = 1.0 # Vref の値を適宜変更してください
# Vin1 から VinN までの値を計算する関数
def calculate_vin_values(Vin0, Vref, steps=10):
vin_values = [Vin0] # Vin0 の初期値をリストに追加
D_values = [] # D の値を保存するリスト
for _ in range(steps):
Vin0 = vin_values[-1] # 現在の Vin の値を取得
if Vin0 > Vref / 4:
D = '10'
Vin_next = 2 * Vin0 - Vref
elif Vin0 > -Vref / 4:
D = '01'
Vin_next = 2 * Vin0
else:
D = '00'
Vin_next = 2 * Vin0 + Vref
vin_values.append(Vin_next)
D_values.append(D)
return vin_values, D_values
# Vin1 から Vin10 までの値を計算
vin_values, D_values = calculate_vin_values(Vin, Vref, steps=10)
# 結果を出力
for i, (vin, D) in enumerate(zip(vin_values[1:], D_values), start=1):
print(f'Step {i}: Vin = {vin}, D = {D}')
# 文字列を定義
binary_string = '1010'
# β進数を10進数に変換する関数を定義
def binary_to_base(binary_string, base):
decimal_number = 0
power = len(binary_string) - 1 # 最上位桁の指数
for digit in binary_string:
decimal_number += int(digit) * (base ** power)
power -= 1
return decimal_number
# β進数に変換して結果を出力(ここではβを置き換えます)
beta_number = binary_to_base(binary_string, 1.7)
print(f"β進数 {binary_string} は10進数で {beta_number} です。")
# 二進数の文字列を定義
binary_string = '1010'
# 二進数を十進数に変換する関数を定義
def binary_to_decimal(binary_string):
decimal_number = 0
power = len(binary_string) - 1 # 最上位桁の指数
for digit in binary_string:
decimal_number += int(digit) * (2 ** power)
power -= 1
return decimal_number
# 二進数を十進数に変換して結果を出力
decimal_number = binary_to_decimal(binary_string)
print(f"二進数 {binary_string} は十進数で {decimal_number} です。")
import numpy as np
import matplotlib.pyplot as plt
import os
import time
# Define parameters
N = 256 # Sampling points
fs = 20e3 # Sampling frequency
beta_sweep_min = 1.60
beta_sweep_max = 1.80
beta_sweep_nums = 1000
# Create dummy data for ADC analysis
bit = 16 # ADC resolution
t = np.arange(0, N) / fs # Time vector
fn = np.linspace(0, N, N)
# Generate a dummy signal for sample (replace the actual loading of data with dummy data)
D = np.random.randint(0, 2, (N, bit)) # Random binary data
sample = 2 * D[:, :N] - 1 # Simulate ADC sample data
# Perform the SNDR calculation
start = time.time()
beta_sweep = np.linspace(beta_sweep_min, beta_sweep_max, beta_sweep_nums)
# Dummy calculations (replace with real calculations in practical use)
weight = np.multiply(beta_sweep - 1, beta_sweep ** np.linspace(-1, -bit, bit).reshape(bit, 1))
y = np.dot(sample, weight).T
F = np.fft.rfft(y) * 2 / N
P = (F * F.conj()).real
Signal = P.max(axis=1)
SNDRs = 10 * np.log10(np.multiply(Signal, (1 / (P[:, 1 : int(N / 2)].sum(axis=1) - Signal))))
beta_time = time.time() - start
print(f"beta推定_time:{beta_time} [sec]")
beta_opt_index = np.argmax(SNDRs)
beta_opt = beta_sweep[beta_opt_index]
y = y[beta_opt_index]
P = P[beta_opt_index]
# SNDR, ENOB calculations
SNDR = SNDRs[beta_opt_index]
P_dB = 10 * np.log10(P / Signal[beta_opt_index])
ENOB = (SNDR - 1.76) / 6.02
# 14-bit normalization
y_decimal = [round((y[n] + 1) * (2**13)) for n in range(N)]
# Generate plots
fig = plt.figure()
plt.title("Normalized Reproduced Wave (N=" + str(N) + ")")
plt.xlabel("Time [ms]")
plt.ylabel("Voltage [V]")
plt.ylim(-1, 1)
plt.grid(True)
plt.plot(t * 1e3, y, drawstyle="steps-post") # Convert time to ms for plotting
plt.show()
# Power spectrum plot
fig = plt.figure()
plt.title("Power Spectrum of the Reproduced Wave (N=" + str(N) + ")")
plt.xlabel("Normalized Frequency (f/fs)")
plt.ylabel("Power [dB]")
plt.text(0.3, -10, "SNDR = " + format(SNDR, ".2f") + "[dB]", size=10)
plt.text(0.3, -20, "ENOB = " + format(ENOB, ".2f") + "[bit]", size=10)
plt.text(0.3, -30, "βopt = " + format(beta_opt, ".6f"), size=10)
plt.ylim(-170, 10)
plt.grid(True)
plt.plot(fn[1 : int(N / 2)] / N, P_dB[1 : int(N / 2)])
plt.show()
# Saving figures (if necessary)
if not os.path.isdir(os.getcwd() + "\\temp"):
os.makedirs(os.getcwd() + "\\temp")
def save_fig(fig, dir_path, fig_name):
if not os.path.isdir(dir_path + "\\eps"):
os.makedirs(dir_path + "\\eps")
fig.savefig(dir_path + "\\eps\\" + fig_name + ".eps")
fig.savefig(dir_path + "\\" + fig_name + ".png")
save_fig(fig, os.getcwd() + "\\temp", "Power_Spectrum")