CMOS2段差動ソース接地増幅オペアンプの設計


差動増幅×ソース接地増幅の2段階増幅
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/fa81a602-93e4-c3c2-4494-fbd62955368a.png)

```py
import math

# Given parameters
rop2 = 1e6   # in ohms (Ω), example value
ron4 = 1e6   # in ohms (Ω), example value
rop6 = 1e6   # in ohms (Ω), example value
ron5 = 1e6    # in ohms (Ω), example value
gm2 = 5e-3   # in Siemens (S), example value
gm5 = 5e-3  # in Siemens (S), example value
Cf = 1e-12   # Capacitance in Farads (F), example value

# Calculate parameters a and b
a = (rop2 * ron4) / (rop2 + ron4)
b = (rop6 * ron5) / (rop6 + ron5)

# Calculate DC gain
DC_gain = gm2 * (rop2 * ron4 / (rop2 + ron4)) * gm5 * (rop6 * ron5 / (rop6 + ron5))

# Convert DC gain to dB
DC_gain_dB = 20 * math.log10(DC_gain)

# Calculate pole frequency (f1)
f1 = 1 / (2 * math.pi * a * (1 + gm5 * b) * Cf)

# Calculate GB product
GB_product = DC_gain * f1

# Print results
print(f"DC Gain: {DC_gain:.4f}")
print(f"DC Gain (dB): {DC_gain_dB:.4f} dB")
print(f"Pole Frequency (f1): {f1:.4f} Hz")
print(f"GB Product: {GB_product:.4f}")


```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/d8d00c6f-27be-d2a8-3e19-619a035ed8a1.png)


定電流電源負荷のソース接地増幅
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/0985e3bb-738e-5651-cc10-c5ac8866b946.png)



```
import math

# Given parameters
gm = 10e-3   # Transconductance in Siemens (S)
rop = 1e6    # Output resistance in ohms (Ω), example value
ron = 1e6    # Input resistance in ohms (Ω), example value
C = 10e-12   # Capacitance in Farads (F)
R = 1e3      # Resistance in ohms (Ω), example value

# Calculate DC gain
DC_gain = gm * (rop * ron / (rop + ron))

# Convert DC gain to dB
DC_gain_dB = 20 * math.log10(DC_gain)

# Calculate mirror effect capacitance
mirror_capacitance = C * (1 + DC_gain)

# Calculate pole frequency (f1)
f1 = 1 / (2 * math.pi * R * mirror_capacitance)

# Print results
print(f"DC Gain: {DC_gain:.4f}")
print(f"DC Gain (dB): {DC_gain_dB:.4f} dB")
print(f"Mirror Effect Capacitance: {mirror_capacitance:.4e} F")
print(f"Pole Frequency (f1): {f1:.4f} Hz")
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/87fe5476-fad7-8f0c-d3da-d9aea7dd1bf0.png)




![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/b36b6c5a-98f6-ae13-5e24-87b4c32cfff9.png)


```
import math

# Given parameters
A1_dB = 20       # Desired gain A1 in dB
A2_dB = 40       # Desired gain A2 in dB
rop2 = 10e3      # Output resistance of M2 in ohms
ron4 = 10e3      # Input resistance of M2 in ohms
rop6 = 10e3      # Output resistance of M5 in ohms
ron5 = 10e3      # Input resistance of M5 in ohms
Cc = 10e-12      # Capacitance Cc in Farads
CL = 100e-12     # Load capacitance CL in Farads

# Calculate a and b
a = (rop2 * ron4) / (rop2 + ron4)
b = (rop6 * ron5) / (rop6 + ron5)

# Calculate gm2 for A1
A1 = 10 ** (A1_dB / 20)
gm2 = A1 / a

# Calculate gm5 for A2
A2 = 10 ** (A2_dB / 20)
gm5 = A2 / b

# Calculate principal frequency f1
f1 = 1 / (2 * math.pi * a * Cc * (A2 + 1))

# Calculate 0 dB frequency GB product
GB_product_0dB = A1 * A2 * f1

# Calculate second frequency f2 assuming very large Cc
f2 = gm5 / (2 * math.pi * CL)

# Print results
print(f"a: {a:.4e}")
print(f"b: {b:.4e}")
print(f"gm2: {gm2:.4e} S")
print(f"gm5: {gm5:.4e} S")
print(f"Principal Frequency (f1): {f1 / 1e6:.4f} MHz")
print(f"0 dB Frequency GB Product: {GB_product_0dB / 1e6:.4f} MHz")
print(f"Second Frequency (f2): {f2 / 1e6:.4f} MHz")


```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/a087d8fa-9419-eaea-1494-4df5d702b1e8.png)



![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/d4c77744-241d-33c1-9131-fbfbe2633f92.png)


fは遮断周波数
```
import math

# Given values
gain_dB = 26
gm = 10e-3  # 10 mS (10 millisiemens)
f = 1e6  # 1 MHz

# Calculate R
gain = 10**(gain_dB / 20)
R = gain / (gm * 10**3)  # converting mS to S

# Calculate C
C = 1 / (2 * math.pi * R * f)

print(f"R ≈ {R/1000:.2f} kΩ")
print(f"C ≈ {C * 1e12:.2f} pF")
```



https://sawazawablog.com/miller_effect/

ソース接地増幅回路の周波数特性
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/405f6741-27ee-4cc7-af9a-26907740bf68.png)



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

# Given parameters (adjust these values as needed)
gm = 35e-6  # Transconductance in siemens
Rd = 50e6   # Drain resistance in ohms
Ci = 1e-12  # Input capacitance in farads
Cc = 1e-12  # Compensation capacitance in farads
Rs = 50e3   # Source resistance in ohms
C0 = 1e-12  # Load capacitance in farads
rL = Rd     # Load resistance

# Calculate gain
gain = gm * Rd
print(f"Gain (gm * Rd): {gain}")

# Calculate Miller effect capacitance
Cm = Ci + Cc * (1 + gain)
print(f"Miller Effect Capacitance (Cm): {Cm}")

# Calculate angular frequencies ωA and ωB
ωA = 1 / (Cm * Rs)
ωB = 1 / (C0 * rL)
print(f"Angular Frequency ωA: {ωA}")
print(f"Angular Frequency ωB: {ωB}")

# Transfer function H(s) = -gm * Rd / [(1 + s/ωA) * (1 + s/ωB)]
numerator = [-gain]
denominator = [1, (1/ωA + 1/ωB), 1/(ωA * ωB)]
system = signal.TransferFunction(numerator, denominator)

# Frequency response
w, mag, phase = signal.bode(system)

# Plot Bode magnitude plot
plt.figure()
plt.semilogx(w, mag)
plt.title('Bode Plot - Magnitude')
plt.xlabel('Frequency [rad/s]')
plt.ylabel('Magnitude [dB]')
plt.grid(which='both', linestyle='-', color='grey')
plt.show()

# Plot Bode phase plot
plt.figure()
plt.semilogx(w, phase)
plt.title('Bode Plot - Phase')
plt.xlabel('Frequency [rad/s]')
plt.ylabel('Phase [degrees]')
plt.grid(which='both', linestyle='-', color='grey')
plt.show()
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3759109/307ab6cb-4c77-a481-e296-36c208bd61b6.png)