I want to understand why this code used tan and cos ?

function [ b, a ] = butterTwoBp( dt, fl, fu ) 
N = (tan(q)^2) + sqrt(2)*tan(q) + 1;
M = (tan(q)^2) / N; %M after N because it depends on N
O = -cos(r) * (2*sqrt(2)*tan(q) + 4) / ((cos(q))*N);
P = (-2*(tan(q)^2) + ((  (2*cos(r))   /  (cos(q))   )^2) + 2 )  /   N;
Q = cos(r)*(2*sqrt(2)*tan(q) - 4)/(cos(q)*N);
R = (   (tan(q)^2) - sqrt(2)*tan(q) + 1   )  /  N;

b=[M 0 -2*M 0 M];
a=[1 O P Q R];

I got this code from https://stackoverflow.com/questions/17340198/what-is-the-command-for-butterworth-bandpass-filter?answertab=active#tab-top

  • $\begingroup$ For the $\cos$ or $\tan$ substitutions, check the bottom of Audio EQ Cookbook by Robert Bristow-Johnson $\endgroup$ Sep 9 '19 at 16:05
  • 1
    $\begingroup$ Many thanks Laurent Duval for your comment. Indeed I need to understand the general benefit from using tan and cos in [a,b] generation as preparation step for the FILTER function in matlab since this function used for transform the discrete signal into z-domain. $\endgroup$ Sep 10 '19 at 19:40
  • 1
    $\begingroup$ @LaurentDuval: You're right about the bilinear transform, but there's no two-pass filtering going on, just an ordinary 4th order Butterworth band pass filter. $\endgroup$
    – Matt L.
    Sep 11 '19 at 13:33
  • $\begingroup$ Yes, I checked afterward the result was not symmetric. I'll update my comment this week-end $\endgroup$ Sep 11 '19 at 22:29

The trigonometric functions enter the calculation because of the use the bilinear transform for transforming an analog filter to a discrete-time filter. The bilinear transform warps the frequencies of the analog filter, that's why we have to pre-warp the frequencies of the analog filter in order to obtain the desired cut-off frequencies of the discrete-time filter.

The frequency warping of the bilinear transform is described by the following equation:


where $\Omega$ is the frequency (in radians) in the analog domain, and $\omega$ is the normalized frequency (in radians) in the discrete-time domain. Eq. $(1)$ is used to pre-warp the specified frequencies to obtain the edge frequencies for designing the analog prototype filter. After applying the bilinear transform to that analog prototype, the resulting discrete-time filter will have the correct edge frequencies.

The design procedure is as follows:

  1. Pre-warp the given edge frequencies according to $(1)$.
  2. Design an analog band pass filter with the pre-warped edge frequencies by applying a frequency transformation to a low pass prototype filter.
  3. Apply the bilinear transform to the analog band pass filter to obtain the desired discrete-time filter.

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.