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?

自作アンプ設計記事のPythonコード計算

Posted at

初心者向け:Pythonで学ぶ1Wオーディオアンプ自作と電源設計シミュレーション

オーディオアンプの自作に挑戦したいけど、「どのくらいの電源電圧が必要?」「スピーカーに1W出すにはどう設計すればいい?」といった疑問を持っていませんか?

本記事では、eDIY-fan.comの解説をもとに、Pythonで簡単にアンプ設計をシミュレーションできるツールを作成しました。


Pythonでのシミュレーションコード

以下のコードをGoogle Colabなどで実行すれば、波形と電源設計を一気に確認できます:


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

# --- 基本パラメータ(スピーカー出力と電源設計) ---
R_speaker = 8
P_target = 1.0
V_peak = np.sqrt(P_target * R_speaker)
V_pp = 2 * V_peak
A = 5.7
Vin_peak = 0.5
Vout_peak = Vin_peak * A
Vcc_opamp = (Vout_peak + 1.5) * 2
Vcc_output = (Vout_peak + 1.3) * 2
Vcc_required = max(Vcc_opamp, Vcc_output)
V_supply = 12.0
Vcc_set = 9.5
I_rms = 0.2
P_loss_Q7 = (V_supply - Vcc_set) * I_rms

# --- サイン波生成 / Generate sine wave ---
t = np.linspace(0, 0.01, 1000)
input_wave = Vin_peak * np.sin(2 * np.pi * 440 * t)
output_wave = Vout_peak * np.sin(2 * np.pi * 440 * t)

# --- 入力カップリングコンデンサによるハイパスフィルタ設計 ---
C1 = 10e-6  # 10uF
R_parallel = 50e3  # R3 || R4 = 50kΩ
fc_calc = 1 / (2 * np.pi * R_parallel * C1)
hp_system = signal.TransferFunction([R_parallel * C1, 0], [R_parallel * C1, 1])
w = np.logspace(-1, 4, 1000)  # 0.1 Hz ~ 10 kHz
w, mag, phase = signal.bode(hp_system, w)

# --- 統合プロット / Combined Plot ---
fig, axs = plt.subplots(2, 1, figsize=(10, 8))

# サイン波入力・出力
axs[0].plot(t * 1000, input_wave, label="Input (0.5V peak)")
axs[0].plot(t * 1000, output_wave, label=f"Output ({Vout_peak:.2f}V peak)", linestyle='--')
axs[0].axhline(Vout_peak, color='r', linestyle=':', alpha=0.5)
axs[0].axhline(-Vout_peak, color='r', linestyle=':', alpha=0.5)
axs[0].set_title("Input and Amplified Output Sine Wave")
axs[0].set_xlabel("Time [ms]")
axs[0].set_ylabel("Voltage [V]")
axs[0].grid(True)
axs[0].legend()

# ハイパスフィルタ特性
axs[1].semilogx(w, mag, label="High-Pass Filter via C1 and R3||R4", color='red')
axs[1].axvline(fc_calc, color='red', linestyle='--', alpha=0.6, label=f"Cutoff = {fc_calc:.2f} Hz")
axs[1].set_title("High-Pass Filter Frequency Response")
axs[1].set_xlabel("Frequency [Hz]")
axs[1].set_ylabel("Gain [dB]")
axs[1].grid(True, which="both")
axs[1].legend()

plt.tight_layout()
plt.show()

# --- コンソール出力 ---
print("【出力条件の計算結果】\n")
print(f"{'必要な出力電力 [W]':<34}: {P_target}")
print(f"{'スピーカー抵抗 [Ω]':<34}: {R_speaker}")
print(f"{'必要な出力振幅 [V]':<34}: {V_peak:.2f}")
print(f"{'出力電圧 Vpp [V]':<34}: {V_pp:.2f}")
print(f"{'入力電圧 (peak) [V]':<34}: {Vin_peak}")
print(f"{'増幅率':<34}: {A}")
print(f"{'出力電圧 (peak) [V]':<34}: {Vout_peak:.2f}")
print(f"{'オペアンプに必要な最小VCC [V]':<34}: {Vcc_opamp:.2f}")
print(f"{'出力段に必要な最小VCC [V]':<34}: {Vcc_output:.2f}")
print(f"{'必要な電源電圧 [V]':<34}: {Vcc_required:.2f}")
print(f"{'設定電源電圧 [V]':<34}: {Vcc_set}")
print(f"{'トランジスタQ7の損失電力 [W]':<34}: {P_loss_Q7:.2f}")
print(f"{'入力カップリングHPFカットオフ周波数 [Hz]':<34}: {fc_calc:.3f}")


【出力条件の計算結果】

必要な出力電力 [W] : 1.0
スピーカー抵抗 [Ω] : 8
必要な出力振幅 [V] : 2.83
出力電圧 Vpp [V] : 5.66
入力電圧 (peak) [V] : 0.5
増幅率 : 5.7
出力電圧 (peak) [V] : 2.85
オペアンプに必要な最小VCC [V] : 8.70
出力段に必要な最小VCC [V] : 8.30
必要な電源電圧 [V] : 8.70
設定電源電圧 [V] : 9.5
トランジスタQ7の損失電力 [W] : 0.50

image.png

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?