I am trying to create a IIR Notch filter in python using a numpy and scipy librairy array to remove the sine tone from the imported wave file (I use the wave module for this). My file was created while listening to Adobe: it is a pure sine @ 1.2 kHz, sampled at 48, 96 or 192 kHz, in order to have “pseudo-periodic” data for my circular fft (just ask if I am clear enough)
Here is the code that I used to implement the coefficient of my filter (I get the coefficient from the article "Design and implementation of the Notre Filter IIR filter of the second order digital signal processing system" CM Wang and WC Xiao )
f_cut = 1200.0
wn = f_cut/rate
r = 0.99
B, A = np.zeros(3), np.zeros(3)
A[0],A[1],A[2] = 1.0, -2.0*r*np.cos(2*np.pi*wn), r*r
B[0],B[1],B[2] = 1.0, -2.0*np.cos(2*np.pi*wn), 1.0
filtered = signal.lfilter(B, A, data_flt_R, axis=0)
Where data_flt_Ris the numpy array containing my right channel in type float64, and rateis my sample rate. I build the frequency response and fft of my data using the matplotlib module to check if everything is ok.
N = len(data_flt_R)
w, h = signal.freqz(B,A, N)
pyplot.subplot(2,1,1)
pyplot.semilogx(w*rate/(2*np.pi), 20*np.log10(np.absolute(h)))
fft1 = fftpack.fft(data_flt_R, N)
fft_abs1 = np.absolute(fft1)
ref = np.nanmax(fft_abs1)
dB_unfiltered = 20*np.log10(fft_abs1/ref)
fft2 = fftpack.fft(filtered, N)
fft_abs2 = np.absolute(fft2)
dB_filtered = 20*np.log10(fft_abs2/ref)
abs = fftpack.fftfreq(N,1.0/rate)
pyplot.subplot(2,1,2)
pyplot.semilogx(abs,dB_unfiltered,'r', label='unfiltered')
pyplot.semilogx(abs,dB_filtered,'b', label='filtered')
pyplot.grid(True)
pyplot.legend()
pyplot.ylabel('power spectrum (in dB)')
pyplot.xlim(10,rate/2)
pyplot.xlabel('frequencies (in Hz)')
And here is what I get:

I do not understand the results and the values that I get before and after my fc. Should I get a plot that looks like red but without a main peak? Why do I have a slope in HF? Is this related to the window?
In addition, the result changes if I change my sampling rate and / or data length (16/24 or 32 bits). Can anyone enlighten me?