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

# Filter parameters
fs = 44100        # Sampling frequency in Hz
f0 = 2000         # Frequency to be removed from signal (notch frequency)
Q = 1      # Quality factor 

# Design notch filter
b, a = iirnotch(f0, Q, fs)

# Display transfer function
print("Numerator coefficients (b):", b)
print("Denominator coefficients (a):", a)

# Optional: frequency response
w, h = freqz(b, a, fs=fs)
plt.plot(w, 20 * np.log10(abs(h)))
plt.title('Notch Filter Frequency Response')
plt.xlabel('Frequency [Hz]')
plt.ylabel('Amplitude [dB]')
plt.grid()
plt.axvline(f0, color='red', linestyle='--', label='Notch Frequency')
plt.legend()
plt.show()

# Optional: show poles and zeros
z, p, k = tf2zpk(b, a)
print("Zeros:", z)
print("Poles:", p)
print("Gain:", k)
Numerator coefficients (b): [ 0.87454801 -1.67856411  0.87454801]
Denominator coefficients (a): [ 1.         -1.67856411  0.74909601]

No description has been provided for this image
Zeros: [0.95967523+0.28111111j 0.95967523-0.28111111j]
Poles: [0.83928206+0.21142763j 0.83928206-0.21142763j]
Gain: 0.8745480065502544