def fftfilt(b, x, *n):
N_x = len(x)<EOL>N_b = len(b)<EOL>if len(n):<EOL><INDENT>n = n[<NUM_LIT:0>]<EOL>if n != int(n) or n <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if n < N_b:<EOL><INDENT>n = N_b<EOL><DEDENT>N_fft = <NUM_LIT:2> ** nextpow2(n)<EOL><DEDENT>else:<EOL><INDENT>if N_x > N_b:<EOL><INDENT>N = <NUM_LIT:2> ** np.arange(np.ceil(np.log2(N_b)), np.floor(np.log2(N_x)))<EOL>cost = np.ceil(N_x / (N - N_b + <NUM_LIT:1>)) * N * (np.log2(N) + <NUM_LIT:1>)<EOL>if len(cost) > <NUM_LIT:0>:<EOL><INDENT>N_fft = N[np.argmin(cost)]<EOL><DEDENT>else:<EOL><INDENT>N_fft = <NUM_LIT:2> ** nextpow2(N_b + N_x - <NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>N_fft = <NUM_LIT:2> ** nextpow2(N_b + N_x - <NUM_LIT:1>)<EOL><DEDENT><DEDENT>N_fft = int(N_fft)<EOL>L = int(N_fft - N_b + <NUM_LIT:1>)<EOL>H = fft(b, N_fft)<EOL>y = np.zeros(N_x, np.float32)<EOL>i = <NUM_LIT:0><EOL>while i <= N_x:<EOL><INDENT>il = np.min([i + L, N_x])<EOL>k = np.min([i + N_fft, N_x])<EOL>yt = ifft(fft(x[i:il], N_fft) * H, N_fft)  <EOL>y[i:k] = y[i:k] + yt[:k - i]  <EOL>i += L<EOL><DEDENT>return y<EOL>
Filter the signal x with the FIR filter described by the
    coefficients in b using the overlap-add method. If the FFT
    length n is not specified, it and the overlap-add block length
    are selected so as to minimize the computational cost of
    the filtering operation.