17def freqResponse(fs, freq, coefs_b, coefs_a=1.):
19 Computes the frequency response of the filter defined with the filter
23 fs: Sampling frequency [Hz]
24 freq: Array of frequencies to compute the response for
25 coefs_b: Forward coefficients (FIR coefficients)
26 coefs_a: Feedback coefficients (IIR)
29 Complex frequency response for frequencies given in array
33 w, H = freqz(coefs_b, coefs_a, worN=Omg)
37def bandpass_fir_design(L, fs, fl, fu, window=hann):
39 Construct a bandpass filter
41 assert fs/2 > fu,
"Nyquist frequency needs to be higher than upper cut-off"
42 assert fu > fl,
"Cut-off needs to be lower than Nyquist freq"
47 fir = np.empty(L, dtype=float)
50 fir[L//2] = (Omg2-Omg1)/np.pi
52 for n
in range(1, L//2):
53 fir[n+L//2] = (np.sin(n*Omg2)-np.sin(n*Omg1))/(n*np.pi)
54 fir[L//2-n] = (np.sin(n*Omg2)-np.sin(n*Omg1))/(n*np.pi)
62def lowpass_fir_design(L, fs, fc, window=hann):
63 assert fs/2 > fc,
"Nyquist frequency needs to be higher" \
67 fir = np.empty(L, dtype=float)
70 fir[L//2] = Omgc/np.pi
72 for n
in range(1, L//2):
73 fir[n+L//2] = np.sin(n*Omgc)/(n*np.pi)
74 fir[L//2-n] = np.sin(n*Omgc)/(n*np.pi)
82def arbitrary_fir_design(fs, L, freq, amps, window='hann'):
84 Last frequency of freq should be fs/2
86 return firwin2(L, freq, amps, fs=fs, window=window)