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?

デジタルフィルター

Last updated at Posted at 2024-07-02

IMG_6396.jpeg

IMG_6397.jpeg

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

# フィルタ係数
H = 1
b = 0.5  # 例として0.5を使用

# 周波数範囲の設定
w, _ = freqz([1], [1])

# 1次ローパスフィルタの周波数応答
b_lp = [H, H]
a_lp = [1, -b]
w, h_lp = freqz(b_lp, a_lp)

# 1次ハイパスフィルタの周波数応答
b_hp = [H, -H]
a_hp = [1, -b]
w, h_hp = freqz(b_hp, a_hp)

# 1次オールパスフィルタの周波数応答
b_ap = [b, -1]
a_ap = [1, -b]
w, h_ap = freqz(b_ap, a_ap)

# ボード線図のプロット
plt.figure(figsize=(12, 8))

# 振幅応答
plt.subplot(2, 1, 1)
plt.plot(w, 20 * np.log10(abs(h_lp)), label='Low-pass Filter')
plt.plot(w, 20 * np.log10(abs(h_hp)), label='High-pass Filter')
plt.plot(w, 20 * np.log10(abs(h_ap)), label='All-pass Filter')
plt.title('Bode Plot - Magnitude Response')
plt.xlabel('Frequency [radians / sample]')
plt.ylabel('Magnitude [dB]')
plt.legend()
plt.grid()

# 位相応答
plt.subplot(2, 1, 2)
plt.plot(w, np.angle(h_lp), label='Low-pass Filter')
plt.plot(w, np.angle(h_hp), label='High-pass Filter')
plt.plot(w, np.angle(h_ap), label='All-pass Filter')
plt.title('Bode Plot - Phase Response')
plt.xlabel('Frequency [radians / sample]')
plt.ylabel('Phase [radians]')
plt.legend()
plt.grid()

plt.tight_layout()
plt.show()

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?