import scipy.signal
import numpy as np
"""
構文: scipy.signal.firwin(numtaps, cutoff, width=None, window='hamming', pass_zero=True, scale=True, nyq=None, fs=None)
pass_zero: True, False, 'bandpass', 'lowpass', 'highpass', 'bandstop'
window :
boxcar, triang , blackman, hamming , hann , bartlett , flattop, parzen,
bohman, blackmanharris, nuttall , barthann, cosine, exponential, tukey , taylor,
kaiser (needs beta) , gaussian (needs standard deviation),
general_cosine (needs weighting coefficients), general_gaussian (needs power, width),
general_hamming (needs window coefficient) , dpss (needs normalized half-bandwidth),
chebwin (needs attenuation)}
"""
COEFF_WIDTH = 4
NUM_COEFFS = 11
SAMPLE_FREQ = 100
CUT_OFFS = [10, 20]
FILTER_TYPE = "bandpass"
WINDOW = "hamming"
coeffs = scipy.signal.firwin(NUM_COEFFS, CUT_OFFS, window=WINDOW, pass_zero=FILTER_TYPE, scale=True, fs=SAMPLE_FREQ)
print(*coeffs, sep=',')
print("No Good") if len(coeffs[coeffs < -1]) + len(coeffs[coeffs > 1 - 1/2**(COEFF_WIDTH - 1)]) else print("IS OK")
coeffs = np.asarray(np.round(coeffs * 2**(COEFF_WIDTH - 1)), dtype=np.int64)
print(*coeffs, sep=",")
coeffs = np.asarray(np.where(coeffs < 0, coeffs + 2**COEFF_WIDTH, coeffs), dtype=np.uint64)
print(*coeffs, sep=",")
print("(", end="")
print(*["(" + str(COEFF_WIDTH) + 'd"' + str(coeff) + '")' for coeff in coeffs], sep=",\n", end=")")
-3.703826560324038e-18,-0.04068736077594257,-0.12858579923434713,-0.07806890642738276,0.20878284966338043,0.3958935452581824,0.20878284966338043,-0.07806890642738276,-0.12858579923434713,-0.04068736077594257,-3.703826560324038e-18
IS OK
0,0,-1,-1,2,3,2,-1,-1,0,0
0,0,15,15,2,3,2,15,15,0,0
((4d"0"),
(4d"0"),
(4d"15"),
(4d"15"),
(4d"2"),
(4d"3"),
(4d"2"),
(4d"15"),
(4d"15"),
(4d"0"),
(4d"0"))