Difference between freqz vs freqresp in scipy? I'm always confused that scipy has


scipy.signal.freqz, but also 
scipy.signal.lti.freqresp / scipy.signal.dlti.freqresp


According to the documentation they all compute the frequency response. Surprisingly, the convention for the b coefficients are exactly opposite (as pointed out in this answer as well), and they use a different default of sample points. Other than that, my interpretation of the documentation is that scipy.signal.freqz should be yield the same as scipy.signal.dlti.freqresp. However I can't get the same results trying it out on a small example:





import scipy
import matplotlib.pyplot as plt

filter_coef = [0.2, 0.8]
w1, h1 = scipy.signal.freqz(filter_coef)

dlti = scipy.signal.dlti(filter_coef[::-1], [1]) # accounting for flipped convention
w2, h2 = dlti.freqresp(n=len(w1))

fig, axes = plt.subplots(2, 1)
axes[0].plot(w1, np.abs(h1), label="freqz")
axes[0].plot(w2, np.abs(h2), label="dlti.freqresp")
axes[1].plot(w1, np.angle(h1), label="freqz")
axes[1].plot(w2, np.angle(h2), label="dlti.freqresp")
plt.legend()
plt.show()


Produces:



It looks like they match in terms of magnitude, but for some reason the phase is flipped.

Any ideas what is the difference here? And more generally, when should I use which version of freqz/freqresp?
The equation of the filter is given as 

$$H(z) = 0.2 + 0.8z^{-1}$$

This can be equivalently described with positive powers of z as:

$$H(z) = \frac{0.2z+0.8}{z}$$

The two equations above are mathematically equivalent. The function freqz specifies that the numerator and denominator polynomials are to be entered in decreasing (negative) powers of z, while freqresp specifies that they are to be entered in positive powers of z. So the OP should use the first form for freqz and the second form for freqresp. In contrast the OP has flipped the order which is the not the same filter.

In general, in order for the filter to be causal, if expressed in positive powers of z it is implied that it also must be divided by poles at the origin, in this case multiplied by $z^{-1}$.

Doing the following will result in the same answer as the result with freqz:

dlti = scipy.signal.dlti(filter_coef, [1,0]) # accounting for positive power convention


Flipping the coefficients, as the OP has done, is the "reverse filter". The reverse filter has the same magnitude response but has zeros at the reciprocal locations on the z-plane, given by $H(z^{-1})$, giving the result that the OP achieved.