# Using Python with scipy.signal firwin, how do I know how many taps/coefficients should be used?

I need to alter an FIR filter which I know very little about. I have a signal which need to be altered, and looking at a Python script used for this task, I see that it uses Scipy's signal library, more specifically the firwin function.

If I input

cutoff_freq = 5400
num_taps = 51
coeffs = signal.firwin(numtaps = num_taps, cutoff = cutoff_freq, window = "hamming", nyq = 72000)


I get

scipy\signal\filter_design.py:338: BadCoefficients: Badly conditioned filter coefficients (numerator): the results may be meaningless

The same occurs when num_taps is 52, 53, 54 and 55, but 56, 57, 58 and 59 does not give this warning. What does this mean and how should I be sure to avoid it?

• What was the original filter like, and what did you change? – JRE Aug 20 '14 at 14:44
• I don't see any reason why this should happen, might be a bug in Scipy. Just as a test try signal.firwin(numtaps=num_taps,cutoff=cutoff_freq) with no further arguments and with cutoff_freq=0.075 (=5400/72000). – Matt L. Aug 20 '14 at 16:16
• It isn't a bug, scipy generates that message on purpose. It actively checks for coefficients close to zero, and removes them from the result set. Looking at the code that generates the message doesn't tell me why it is done, though. – JRE Aug 20 '14 at 18:37
• @JRE: Of course Scipy generates that message on purpose. But the fact that it is generated in this case I would call a bug. There's no problem with some filter coefficients being close to zero. They can't just remove them from the result (i.e. from the vector 'coeffs'), this wouldn't make any sense. – Matt L. Aug 20 '14 at 18:56
• Yeah, but that is precisely what scipy does. It is working as designed - someone made the decision to do exactly what I described. If it is a bug, then not an accidental one. There is some discussion in the scipy community about what to do with the situation. They do mention that changing the corner frequency of the sampling rate can cause the warning to go away. As we see here, changing the number of taps can also get rid of the warning. – JRE Aug 20 '14 at 19:41