# Bode plot of discrete-time transfer function $H(z)$

$H(z)$ is the transfer function of a biquad filter as described here.

I would like to plot the Bode plot of the magnitude response of $H(z)$.

Scipy has a bode method (scipy.signal.bode) for continuous-time transfer functions. Is there an option I didn't see for discrete-time functions?

I found in this nice file formula 18. I tried plotting it with gnuplot directly, but that didn't look correct.

set samples 100000, 100000
set logscale x

b0= 0.2514
b1= 0.5028
b2= 0.2514
a1=-0.1712
a2= 0.1768

H(x) = sqrt((b0**2 + b1**2 + b2**2 + 2*(b0*b1+b1*b2)*cos(x) + 2*b0*b2*cos(2*x))/(1 + a1**2 + a2**2 + 2*(a1+a1*a2)*cos(x) + 2*a2*cos(2*x)))

plot [1:22050] H(x)


So, how do I do this? Is it even possible to Bode plot the magnitude response of a discrete-time transfer function?

You can use the freqz command, available in Matlab/Octave and SciPy. In SciPy it is available as scipy.signal.freqz.

For your case it would be scipy.signal.freqz([b0, b1, b2], [a1, a2])

• Understood! The x-axis is "normalized frequency", usually in units of radians/sample going from 0 to $2\pi$ where $2\pi$ corresponds to the sampling rate in radians/sec. So to concert your x-axis to frequency, multiply by your sampling rate in Hz and divide by $2\pi$ Jun 26, 2016 at 12:43
• @kiigass Note that the freqz function of Matlab, plots the log-magnitude vs linear frequency from $w=0$ to $\omega=\pi$ (actually it's further scaled into the $[0,1]$ interval). The bode plot, on the other hand, requires a $\log_{10}(\omega)$ frequency scaling but this is not something preferred for discrete-time frequency response plots, where log frequency axis do not make much sense. Jun 26, 2016 at 13:43