# 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])

Here is the reference for more info:

http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.freqz.html

• I have trouble scaling the x-axis. The given parameters are for a low pass with cutoff frequency at 10kHz, Sampling rate 44,1kHz. How can I scale my x-axis accordingly? Just converting rad -> degree is obviously not sufficient. Jun 26 '16 at 12:04
• 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 '16 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 '16 at 13:43
• i up-arrowed you @Fat32, but i disagree with the last clause of your last sentence. is as important or as unimportant to view frequency response in log frequency scale in discrete-time as in continuous-time. Jun 27 '16 at 5:09
• @robertbristow-johnson thanks for reminding! actually I also didn't like my last statement, as there are cases where it is useful to have a log frequency plot... Jun 27 '16 at 11:34