I have designed a 2nd order low pass butterworth filter for the following:

Sampling Frequency: 10kHz. Cut-off Frequency: 1kHz

After doing a bit of maths I worked out the difference equation:

w=tan(1000*pi / 10000) = 0.3249 
H(Z) = 0.06747(z + 1)^2 / z^2 - 1.143z +0.413 

Poles / Zeroes:

a1=1.143, a2=-0.413, b0=0.06747, b1=0.13494, b2=0.06747 

Difference Equation:

$$y[n] = 0.06747x[n] + 0.13494x[n-1] + 0.06747x[n-2] + 1.143y[n-1] - 0.413y[n-2]$$

Difference Equation in C#

Y[n] = a1 * Y[n - 1] + a2 * Y[n - 2] + b0 * Signal[n] + b1 * Signal[n - 1] + b2 * Signal[n - 2];

The problem I'm having is trying to plot the frequency response using a Bode Diagram (i.e the low pass filter curve).

I'm struggling to understand how the difference equation can be used to plot the bode diagram. How can I do it? I understand that it must be dB magnitude.

To get Y[n] I need to input a signal into the Signal[n] array. I should be able to produce a graph that looks something like this:



You can evaluate the frequency response by evaluating $H(z)$ in the unit circle: $H(e^{j\theta})$, where $\theta$ is the discrete-time frequency.

If you prefer a frequency in Hz, then use $\theta = 2\pi/f_s$ (i.e. the sampling frequency corresponds to $\theta = 2\pi$).

The above expression will give you the frequency response as a complex number, signifying both amplitude and phase response.

If you don't have access to complex number algebra on your platform, use either GNU Octave or Matlab to plot the frequency response (using the function freqz, which takes the a and b coefficients you have already).

Note that Bode diagram refers to an asymptotic approximation of the frequency response, valid only in continuous time systems.

  • $\begingroup$ I think the last sentence is pretty important! What OP wants is a magnitude response. $\endgroup$ Jan 25 '17 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.