I'm trying to implement 2 lowpass filters and see the difference between them from plots( one FIR filter that needs to be designed with the Hann window method and another IIR filter using Chebyshev type I). The problem is that I can't make 2 correct plots to see the difference between them and I don't know exactly if they are correctly implemented...I have fc1,fc2, ft, rp and rs as parameters. Here it's my python code:
import matplotlib.pyplot as plt
import scipy.signal as signal
import numpy as np
def plotInTime(x,fs):
t=np.arange(0,np.size(x,0)/fs,1/fs)
plt.figure()
plt.plot(t,x)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.grid(True)
def plotInFrequency(x,fs):
N=int(np.size(x,0)/2)
if np.size(x,0)==1:
X=np.fft.fft(x,axis=1)
else:
X=np.fft.fft(x,axis=0)
X=np.abs(X)
X=X[:N]
f=np.arange(0,fs/2,fs/2/N)
plt.figure()
plt.plot(f,X)
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.grid(True)
fs, x = readWav('Ring05c.wav')
plt.close('all')
plt.figure(figsize=[12,12])
plt.subplot(3,2,1)
plotInTime(x,fs)
plt.title('Original Signal')
plt.subplot(3,2,2)
myDSP.plotInFrequency(x,fs)
plt.title('Spectrum for the Original Signal')
fc1=1200
fc2=3000
fc= np.arange(fc1,fc2+1)
ft=150
rp=0.1
rs=40
t = np.linspace(-1, 1, 201)
L, Wn = signal.cheb1ord(fc1/(fs/2), fc2/(fs/2), rp, rs);
b, a = signal.cheby1(L, 1, Wn,'low')
h = signal.lfilter(b, a,x,axis=0)
plotInFrequnecy(h,fs)
w=signal.hann(65) #idk what to do after this