-
Notifications
You must be signed in to change notification settings - Fork 35
/
plot_impulse_fresponse.py
executable file
·51 lines (40 loc) · 1.2 KB
/
plot_impulse_fresponse.py
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
45
46
47
48
49
50
51
#!/usr/bin/python3
import matplotlib.pyplot as plt
import numpy as np
import sys
# Plots the impulse response of the Bandstop and its frequency response
def plot_if(figno,name,figtitle):
plt.figure(figno)
plt.suptitle(figtitle)
fs = 250
y = np.loadtxt(name);
plt.subplot(311)
plt.title("Impulse response")
plt.plot(y);
#
# Fourier Transform
yf = np.fft.fft(y)
plt.subplot(312)
fx = np.linspace(0,fs,len(yf))
plt.plot(fx,20*np.log10(abs(yf)))
plt.xlim(0,fs/2)
plt.title("Frequency response")
plt.xlabel("f/Hz")
plt.ylabel("gain/dB")
plt.subplot(313)
p = -np.diff(np.unwrap(np.angle(yf))) / np.diff(fx * 2 * np.pi)
plt.plot(np.linspace(0,fs,len(yf)-1),p)
plt.xlim(0,fs/2)
plt.ylim(-0.075,0.075)
plt.title("Phase response")
plt.xlabel("f/Hz")
plt.ylabel("delay/secs")
if len(sys.argv) < 2:
print("Specify which filter shall be plotted: butterworth, bessel, chebyshevI, chebyshevII.")
quit()
prefix = "target/surefire-reports/"+sys.argv[1]+"/"
plot_if(1,prefix+"lp.txt","Lowpass")
plot_if(2,prefix+"hp.txt","Highpass")
plot_if(3,prefix+"bs.txt","Bandstop")
plot_if(4,prefix+"bp.txt","Bandpass")
plt.show()