0
1

ボード線図とアンプ

Posted at
import sympy as sp

# Define symbols
K, V_GS, V_T, lambda_, V_DS, dV_GS, dV_DS, v_gs, v_ds = sp.symbols('K V_GS V_T lambda_ V_DS dV_GS dV_DS v_gs v_ds')

# Define the main equation
I_Ds_star = K * (V_GS - V_T)**2 * (1 + lambda_ * V_DS)

# Compute the derivatives
dI_Ds_dV_GS = sp.diff(I_Ds_star, V_GS)
dI_Ds_dV_DS = sp.diff(I_Ds_star, V_DS)

# Define the small-signal parameters
g_m = dI_Ds_dV_GS
r_o_inv = dI_Ds_dV_DS

# Express the differential form
dI_Ds = dI_Ds_dV_GS * dV_GS + dI_Ds_dV_DS * dV_DS
i_d = g_m * v_gs + (1 / (1/r_o_inv)) * v_ds

# Substitute numerical values
substitutions = {
    K: 1e-3,       # Example value for K (A/V^2)
    V_GS: 2,       # Example value for V_GS (V)
    V_T: 1,        # Example value for V_T (V)
    lambda_: 0.02, # Example value for lambda (1/V)
    V_DS: 5,       # Example value for V_DS (V)
    dV_GS: 0.01,   # Small change in V_GS (V)
    dV_DS: 0.01,   # Small change in V_DS (V)
    v_gs: 0.01,    # Small signal voltage v_gs (V)
    v_ds: 0.01     # Small signal voltage v_ds (V)
}

# Calculate the numerical values
I_Ds_star_val = I_Ds_star.subs(substitutions)
g_m_val = g_m.subs(substitutions)
r_o_inv_val = r_o_inv.subs(substitutions)
dI_Ds_val = dI_Ds.subs(substitutions)
i_d_val = i_d.subs(substitutions)

I_Ds_star_val, g_m_val, r_o_inv_val, dI_Ds_val, i_d_val


import sympy as sp
import matplotlib.pyplot as plt
import numpy as np

# Define symbols for resistances and transconductances
r2, r4, r6, r7, gm2, gm6 = sp.symbols('r2 r4 r6 r7 gm2 gm6')

# Calculate parallel resistances
rp1 = r2 * r4 / (r2 + r4)
rp2 = r6 * r7 / (r6 + r7)

# Initial stage gain (Differential Amplifier)
A1 = gm2 * rp1

# Output stage gain (Source Follower)
A2 = gm6 * rp2 / (1 + gm6 * rp2)

# Voltage gain
Av = A1 * A2

# Substitute numerical values
substitutions = {
    r2: 1e3,    # Example value for r2 in ohms
    r4: 2e3,    # Example value for r4 in ohms
    r6: 1e3,    # Example value for r6 in ohms
    r7: 2e3,    # Example value for r7 in ohms
    gm2: 1e-3,  # Example value for gm2 in siemens
    gm6: 1e-3   # Example value for gm6 in siemens
}

# Calculate numerical values
rp1_val = float(rp1.subs(substitutions))
rp2_val = float(rp2.subs(substitutions))
A1_val = float(A1.subs(substitutions))
A2_val = float(A2.subs(substitutions))
Av_val = float(Av.subs(substitutions))

# Convert gains to dB
A1_dB = 20 * np.log10(A1_val)
A2_dB = 20 * np.log10(A2_val)
Av_dB = 20 * np.log10(Av_val)

# Display the results
print(f"rp1: {rp1_val} Ohms")
print(f"rp2: {rp2_val} Ohms")
print(f"A1: {A1_val} ({A1_dB:.2f} dB)")
print(f"A2: {A2_val} ({A2_dB:.2f} dB)")
print(f"Av: {Av_val} ({Av_dB:.2f} dB)")

# Plotting
fig, axs = plt.subplots(2, 1, figsize=(10, 10))

# Plot in linear scale (倍)
values = [A1_val, A2_val, Av_val]
labels = ['A1', 'A2', 'Av']
colors = ['red', 'orange', 'purple']

axs[0].bar(labels, values, color=colors)
axs[0].set_title('Circuit Gains (倍)')
axs[0].set_ylabel('Gain')

# Plot in dB scale (デシベル)
values_dB = [A1_dB, A2_dB, Av_dB]
labels_dB = ['A1 (dB)', 'A2 (dB)', 'Av (dB)']

axs[1].bar(labels_dB, values_dB, color=colors)
axs[1].set_title('Circuit Gains (dB)')
axs[1].set_ylabel('Gain (dB)')

# Show the plots
plt.tight_layout()
plt.show()


import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

# Given parameters
gm1 = 2e-3  # 2 mS
gm6 = 10e-3  # 10 mS
r1 = r3 = 40e3  # 40 kΩ
r6 = r7 = 2.1e3  # 2.1 kΩ
rp1 = 20e3  # 20 kΩ
rp2 = 1e3  # 1 kΩ
Cp1 = 0.5e-12  # 0.5 pF
Cp2 = 3e-12  # 3 pF
Cf = 5e-12  # 5 pF
A1 = gm1 * rp1
A2 = gm6 * rp2

# DC Gain (直流ゲイン)
A0 = A1 * A2  # 直流ゲイン

# Pole frequencies before and after compensation
f_p1_before = 1 / (2 * np.pi * Cp1 * rp1)
f_p1_after = 1 / (2 * np.pi * (Cp1 + 50e-12) * rp1)  # 50 pF is the Miller capacitance
f_p2_before = 1 / (2 * np.pi * Cp2 * rp2)
f_p2_after = gm6 / (2 * np.pi * Cf)

# Transfer function Av(jf)
s1 = signal.TransferFunction([A0], [1/(2*np.pi*f_p1_after), 1])
s2 = signal.TransferFunction([1], [1/(2*np.pi*f_p2_after), 1])
Av = signal.TransferFunction([A0], np.convolve(s1.den, s2.den))

# Bode plot
w, mag, phase = signal.bode(Av)

plt.figure(figsize=(10, 8))

# Magnitude plot
plt.subplot(2, 1, 1)
plt.semilogx(w/(2*np.pi), mag)  # Frequency in Hz
plt.title('Bode Plot of the Compensated Amplifier')
plt.ylabel('Magnitude (dB)')
plt.grid(which='both', axis='both')

# Phase plot
plt.subplot(2, 1, 2)
plt.semilogx(w/(2*np.pi), phase)  # Frequency in Hz
plt.xlabel('Frequency (Hz)')
plt.ylabel('Phase (degrees)')
plt.grid(which='both', axis='both')

plt.tight_layout()
plt.show()

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

# Given parameters
A0 = 400  # DC gain
f1 = 160e3  # First pole frequency in Hz (P1)
f2 = 530e6  # Second pole frequency in Hz (P2)

# Define the transfer function
# s = jω where ω = 2 * π * f
s1 = 2 * np.pi * f1
s2 = 2 * np.pi * f2

# Transfer function: A0 / ((1 + s/s1) * (1 + s/s2))
num = [A0]  # Numerator (A0)
den = [1/(s1 * s2), 1/s1 + 1/s2, 1]  # Denominator coefficients

# Create transfer function system
system = signal.TransferFunction(num, den)

# Frequency range for the Bode plot (logarithmic scale)
frequencies = np.logspace(3, 9, 500)  # From 1 kHz to 1 GHz

# Compute Bode plot (magnitude and phase)
w, mag, phase = signal.bode(system, 2 * np.pi * frequencies)

# Plot Bode magnitude plot
plt.figure(figsize=(10, 6))
plt.subplot(2, 1, 1)
plt.semilogx(frequencies, mag)  # Bode magnitude plot
plt.title('Bode Plot of Transfer Function')
plt.ylabel('Magnitude (dB)')
plt.grid(True, which='both')

# Plot Bode phase plot
plt.subplot(2, 1, 2)
plt.semilogx(frequencies, phase)  # Bode phase plot
plt.xlabel('Frequency (Hz)')
plt.ylabel('Phase (degrees)')
plt.grid(True, which='both')

# Show plots
plt.tight_layout()
plt.show()

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

# Given parameters
gm = 10e-3  # Transconductance (S)
Rd = 1e3    # Drain resistance (ohms)
Ci = 10e-12 # Input capacitance (F)
Co = 5e-12  # Output capacitance (F)
Rs = 50     # Source resistance (ohms)

# Define the angular frequency s = jω where ω = 2πf
# Numerator: -gm * Rd
num = [-gm * Rd]

# Denominator: (1 + jωCiRs) * (1 + jωCoRd)
# Transfer function in terms of s = jω
den = [Ci * Co * Rs * Rd, Ci * Rs + Co * Rd, 1]

# Create transfer function system
system = signal.TransferFunction(num, den)

# Frequency range for the Bode plot (logarithmic scale)
frequencies = np.logspace(3, 9, 500)  # From 1 kHz to 1 GHz

# Compute Bode plot (magnitude and phase)
w, mag, phase = signal.bode(system, 2 * np.pi * frequencies)

# Plot Bode magnitude plot
plt.figure(figsize=(10, 6))
plt.subplot(2, 1, 1)
plt.semilogx(frequencies, mag)  # Bode magnitude plot
plt.title('Bode Plot of Transfer Function G')
plt.ylabel('Magnitude (dB)')
plt.grid(True, which='both')

# Plot Bode phase plot
plt.subplot(2, 1, 2)
plt.semilogx(frequencies, phase)  # Bode phase plot
plt.xlabel('Frequency (Hz)')
plt.ylabel('Phase (degrees)')
plt.grid(True, which='both')

# Show plots
plt.tight_layout()
plt.show()


import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

# Given parameters
gm = 10e-3  # Transconductance (S)
Rd = 1e3    # Drain resistance (ohms)
CM = 10e-12 # Capacitance C_M (F)
Co = 5e-12  # Output capacitance C_o (F)
Rs = 50     # Source resistance (ohms)
rL = 1e3    # Load resistance (ohms)

# Calculate pole frequencies (angular)
omega_A = 1 / (CM * Rs)  # First pole angular frequency
omega_B = 1 / (Co * rL)  # Second pole angular frequency

# Define the transfer function
# Numerator: -gm * Rd
num = [-gm * Rd]

# Denominator: (1 + jω/ω_A) * (1 + jω/ω_B)
# Transfer function in terms of s = jω
den = [1/(omega_A * omega_B), 1/omega_A + 1/omega_B, 1]

# Create transfer function system
system = signal.TransferFunction(num, den)

# Frequency range for the Bode plot (logarithmic scale)
frequencies = np.logspace(3, 9, 500)  # From 1 kHz to 1 GHz

# Compute Bode plot (magnitude and phase)
w, mag, phase = signal.bode(system, 2 * np.pi * frequencies)

# Plot Bode magnitude plot
plt.figure(figsize=(10, 6))
plt.subplot(2, 1, 1)
plt.semilogx(frequencies, mag)  # Bode magnitude plot
plt.title('Bode Plot of Transfer Function G(ω)')
plt.ylabel('Magnitude (dB)')
plt.grid(True, which='both')

# Plot Bode phase plot
plt.subplot(2, 1, 2)
plt.semilogx(frequencies, phase)  # Bode phase plot
plt.xlabel('Frequency (Hz)')
plt.ylabel('Phase (degrees)')
plt.grid(True, which='both')

# Show plots
plt.tight_layout()
plt.show()


import numpy as np
import matplotlib.pyplot as plt

# Given parameters
A0 = 400  # DC gain
f1_comp = 160e3  # compensated first pole frequency in Hz (160 kHz)
f2_comp = 530e6  # compensated second pole frequency in Hz (530 MHz)

# Frequency range for the Bode plot (logarithmic scale)
frequencies = np.logspace(3, 9, 1000)  # from 1 kHz to 1 GHz

# Angular frequencies
omega = 2 * np.pi * frequencies

# Calculate the complex gain Av(jf) with compensated poles
Av_jw_comp = A0 / ((1 + 1j * frequencies / f1_comp) * (1 + 1j * frequencies / f2_comp))

# Magnitude and Phase of the gain with compensation
magnitude_comp = 20 * np.log10(np.abs(Av_jw_comp))
phase_comp = np.angle(Av_jw_comp, deg=True)

# Plotting the Bode plot with compensation
plt.figure(figsize=(10, 8))

# Magnitude plot
plt.subplot(2, 1, 1)
plt.semilogx(frequencies, magnitude_comp)
plt.title('Compensated Bode Plot of the Amplifier')
plt.ylabel('Magnitude (dB)')
plt.grid(True)

# Phase plot
plt.subplot(2, 1, 2)
plt.semilogx(frequencies, phase_comp)
plt.ylabel('Phase (degrees)')
plt.xlabel('Frequency (Hz)')
plt.grid(True)

plt.tight_layout()
plt.show()



import numpy as np
import matplotlib.pyplot as plt

# 定数の定義
gm1 = 2e-3    # S
gm6 = 10e-3   # S
r1_r3 = 40e3  # Ω
r6_r7 = 2e3   # Ω
rp1 = 20e3    # Ω
rp2 = 1e3     # Ω
Cp1 = 0.5e-12 # F
Cp2 = 3e-12   # F
Cf = 5e-12    # F

# 直流ゲイン
A0 = gm1 * rp1 * gm6 * rp2
A0_db = 20 * np.log10(A0)

# ミラー容量
CM = gm6 * Cf

# 極の計算
fp1 = 1 / (2 * np.pi * Cp1 * rp1)
f1 = 1 / (2 * np.pi * CM * rp1)
fp2 = 1 / (2 * np.pi * Cp2 * rp2)
f2 = gm6 / (2 * np.pi * Cp2)

# 周波数範囲の設定
frequencies = np.logspace(3, 9, 1000)  # 1kHz to 1GHz

# 利得計算
def gain(f):
    omega = 2 * np.pi * f
    return A0 / np.sqrt((1 + (omega / (2 * np.pi * f1))**2) * (1 + (omega / (2 * np.pi * f2))**2))

# 位相計算
def phase(f):
    omega = 2 * np.pi * f
    return -np.arctan(omega / (2 * np.pi * f1)) - np.arctan(omega / (2 * np.pi * f2))

gain_db = 20 * np.log10(gain(frequencies))
phase_deg = np.degrees(phase(frequencies))

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

# ゲインプロット
plt.subplot(2, 1, 1)
plt.semilogx(frequencies, gain_db)
plt.title('Bode Plot')
plt.ylabel('Gain (dB)')
plt.axhline(y=0, color='k', linestyle='--', linewidth=0.5)
plt.axvline(x=f1, color='r', linestyle='--', label=f'f1 = {f1/1e6:.2f} MHz')
plt.axvline(x=f2, color='g', linestyle='--', label=f'f2 = {f2/1e6:.2f} MHz')
plt.legend()

# 位相プロット
plt.subplot(2, 1, 2)
plt.semilogx(frequencies, phase_deg)
plt.ylabel('Phase (degrees)')
plt.xlabel('Frequency (Hz)')
plt.axhline(y=-180, color='k', linestyle='--', linewidth=0.5)
plt.axvline(x=f1, color='r', linestyle='--')
plt.axvline(x=f2, color='g', linestyle='--')

plt.tight_layout()
plt.show()









0
1
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
1