0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

アナログデジタルNAND回路

Last updated at Posted at 2024-12-17

アナログデジタルNAND回路

function [analog_out, digital_bit1, digital_bit2] = nand_analog_digital(V1, V2, VDD)
% 入力:
% V1: 入力電圧1
% V2: 入力電圧2
% VDD: 電源電圧
%
% 出力:
% analog_out: アナログ出力
% digital_bit1: デジタル出力1 (中間NANDの状態)
% digital_bit2: デジタル出力2 (反転状態)

% 閾値電圧
Vth = VDD / 2;

% 論理NAND動作(デジタルビット)
if (V1 > Vth) && (V2 > Vth)
    digital_bit1 = 0; % 両方が高い場合 -> 0
else
    digital_bit1 = 1; % それ以外 -> 1
end

% デジタル出力2: 反転 (NOT)
digital_bit2 = ~digital_bit1;

% アナログ出力: NAND結果に応じて電源電圧または0V
if digital_bit1 == 1
    analog_out = VDD; % 高い場合 -> VDD
else
    analog_out = 0;   % 低い場合 -> 0V
end
end

image.png

Python

import numpy as np
import matplotlib.pyplot as plt

# パラメータ設定
VDD = 5  # 電源電圧 (V)
Vth = 2.5  # 閾値電圧 (V)
k = 10  # ゲイン

# 入力電圧1と入力電圧2
V_in1 = np.linspace(0, 5, 100)
V_in2 = np.linspace(0, 5, 100)

# シグモイド関数を使用した出力計算
def sigmoid(V_in, VDD, Vth, k):
    return VDD / (1 + np.exp(-k * (V_in - Vth)))

# 出力電圧1と出力電圧2
V_out1 = sigmoid(V_in1, VDD, Vth, k)
V_out2 = sigmoid(V_in2, VDD, Vth, k)

# 閾値に基づいて最終出力電圧を決定
def apply_threshold(V_out, Vth, VDD):
    return np.where(V_out > Vth, VDD, 0)

V_final1 = apply_threshold(V_out1, Vth, VDD)
V_final2 = apply_threshold(V_out2, Vth, VDD)

# NAND回路: 出力を決定
V_out = np.logical_not(np.logical_and(V_final1, V_final2))  # NAND回路

# プロット
plt.figure(figsize=(10, 6))

# 入力電圧1と出力電圧1
plt.subplot(2, 1, 1)
plt.plot(V_in1, V_out1, label="V_out1 (Sigmoid)")
plt.plot(V_in1, V_final1, label="V_final1 (Threshold)", linestyle="--")
plt.title("Input Voltage 1 and Output Voltage 1")
plt.xlabel("Input Voltage (V)")
plt.ylabel("Output Voltage (V)")
plt.legend()

# 入力電圧2と出力電圧2
plt.subplot(2, 1, 2)
plt.plot(V_in2, V_out2, label="V_out2 (Sigmoid)")
plt.plot(V_in2, V_final2, label="V_final2 (Threshold)", linestyle="--")
plt.title("Input Voltage 2 and Output Voltage 2")
plt.xlabel("Input Voltage (V)")
plt.ylabel("Output Voltage (V)")
plt.legend()

# 最終出力のプロット
plt.figure(figsize=(10, 6))
plt.plot(V_in1, V_out, label="V_out (NAND output)", color='r')
plt.title("Final NAND Output")
plt.xlabel("Input Voltage (V)")
plt.ylabel("Output Voltage (V)")
plt.legend()

plt.tight_layout()
plt.show()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?