-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheby2filter.py
More file actions
44 lines (34 loc) · 1.06 KB
/
cheby2filter.py
File metadata and controls
44 lines (34 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# written by: gunnar pope
# gunnar.c.pope.th@dartmouth.edu
# date: 7/20/17
# a script implementing a chebyshev type II digital filter
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import scipy
import scipy.signal as filt
def filter_cheby2(input_signal,fsamp,fpass,fstop):
#the normalized passband frequency
wp = fpass/fnyq
ws = fstop/fnyq
dB_pb = 3 #the max loss in the passband (dB)
dB_sb = 74 #attenuation in the stop band
N, Wn = filt.cheb2ord(wp, ws, dB_pb, dB_sb)
b, a = filt.cheby2(N, dB_sb, Wn, 'lowpass')
output_signal = scipy.signal.filtfilt(b, a, input_signal)
return output_signal
if __name__ == "__main__":
# the filter settings
fsamp = 2 # Hz
fnyq = fsamp / 2
fpass = 0.6 # Hz
fstop = 0.9 # Hz
t = np.linspace(0,4,100)
f = np.sin(2*pi*0.5*t) + np.cos(2*pi*60*t)
f_filt = filter_cheby2(f,fsamp,fpass,fstop)
plt.plot(f)
plt.plot(f_filt)
plt.title('Chebyshev type II low pass filter')
plt.xlabel('time')
plt.ylabel('amplitude')
plt.show()