what is the theory behind Butter function? I want to understand why this code used tan and cos ? 

function [ b, a ] = butterTwoBp( dt, fl, fu ) 
q=pi*dt*(fu-fl);
r=pi*dt*(fu+fl);
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
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:

$$\Omega=\tan\left(\frac{\omega}{2}\right)\tag{1}$$

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:


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