# How to deal with [h] coefficients which are 0 from sos-matrix

Calling scipy.signal.sosfreqz with a sos-matrix describing an ordinary butterworth bandpass returns an array of h coefficients, of which the one at index 0 is of value 0.0+j0.0. A problem arises when the filter needs to be scaled to 0dB plotted via

plt.semilogx(f, np.array([20 * m.log10(abs(value)) for value in h]), label=None)


which runs into a ValueError: math domain error because the first h-value causes log10(0) which does not exist. Matlab somehow handles this implicitly. How could i modify/ignore h[0] in a scientifically correct manner?

Python code to reproduce:

sample_f = 48000
nyquist = sample_f / 2
_sos = signal.butter(6, [18245 / nyquist , 22988 / nyquist], btype='band', output='sos')
f, h = signal.sosfreqz(_sos,worN=sample_f)
print(abs(h[0])) # is zero
plt.semilogx(f, np.array([20 * m.log10(abs(value)) for value in h]), label=None)


The correct answer for at these frequencies is $$-\infty$$ which of course you can't plot.
1. Add a small offset that's related to the dynamic range you want to see. Something like h[0] = 1e-10 would cap the plot at -200dB.
2. Just exclude the offending frequency from your plot. Something like semilogx(f[1:],h[1:])