# Digital Signal Processing/Bilinear Transform
## The Bilinear Transform

The Bilinear transform is a mathematical relationship which can be used to convert the transfer function of a particular filter in the complex Laplace domain into the z-domain, and vice-versa. The resulting filter will have the same characteristics of the original filter, but can be implemented using different techniques. The Laplace Domain is better suited for designing analog filter components, while the Z-Transform is better suited for designing digital filter components.
The bilinear transform is the result of a numerical integration of the analog transfer function into the digital domain. We can define the bilinear transform as:
    $s={\frac {2(1-z^{-1})}{T(1+z^{-1})}}$
The bilinear transform can be used to produce a piecewise constant magnitude response that approximates the magnitude response of an equivalent analog filter. The bilinear transform does not faithfully reproduce the analog filters phase response, however.
As example, the phase response for the bilinear equivalent to an analog system is shown next, using a sampling frequency of 40 rad/sec. Compare the phase responses in the plot, realizing the limit is Ws/2=20 rad/s - the clear divergence is evident.
    $y1/u1={\frac {s^{5}+11.21s^{4}+116.2s^{3}+372.6s^{2}+561.6s+363.5}{s^{7}+26.49s^{6}+340.5s^{5}+2462s^{4}+1.043e+04s^{3}+2.336e+04s^{2}+1.905e+04s+4982}}$
* num = [1 11.21 116.242 372.601 561.589 363.528 ];
* den= [1 26.489 340.47 2461.61 10433.1 23363.9 19049. 4981.82 ];
* C=tf(num,den); % GNU Octave command
* D=c2d(C,2*pi/40,'bi'); % A/D via Octave
    $y1/u1={\frac {0.002524z^{7}-0.00226z^{6}-0.003061z^{5}+0.004265z^{4}-0.001063z^{3}-0.001333z^{2}+0.001663z-0.0006096}{z^{7}-3.545z^{6}+5.43z^{5}-4.798z^{4}+2.702z^{3}-0.9835z^{2}+0.2186z-0.02319}}$
Note that two zeros have been added so that zero and pole counts match.
* Phase discrep approaching Ws/2

## W Domain

The bilinear transform is a one-to-one mapping, that is that a unique point in one domain will be transformed into a unique point in the other domain. However, the transformation is not a linear transformation, and is not an exact equivalency between Laplace and Z domains. If a digital filter is designed and transformed into an analog filter, the resulting poles and zeros are not located on the s-plane, but instead on the w-plane that has similar properties, but with a nonlinear correspondence.
In the bilinear transform, the positive imaginary axis in the s-domain is transformed into the upper-half unit circle in the z-domain. Likewise, the negative imaginary axis in the s-domain is transformed into the lower-half unit circle in the z-domain. This mapping is highly nonlinear, however, resulting in a phenomena known as "frequency warping".

## Prewarping

Frequency warping follows a known pattern, and there is a known relationship between the warped frequency and the known frequency. We can use a technique called prewarping to account for the nonlinearity, and produce a more faithful mapping.
    $\omega _{p}={\frac {2}{T}}\tan \left({\frac {\omega T}{2}}\right)$
The p subscript denotes the prewarped version of the same frequency. Note that in the limit $T\to 0$, the continuous solution is $\omega _{p}\to \omega$.

## Phase

The bilinear transform does not maintain phase characteristics of the analog filter, and there is no way to correct the phase response to match.

## Filter Design Steps

When designing a digital filter using an analog approximation and the bilinear transform, we follow these steps:
* Prewarp the cutoff frequencies
* Design the necessary analog filter
* Apply the bilinear transform to the transfer function
* Normalize the resultant transfer function to be monotonic and have a unity passband gain (0dB).
Alternatively, if we have an inverse bilinear transform, we can follow these steps:
* Use the inverse bilinear transform on the filter specifications in the digital domain to produce equivalent specifications in the analog domain.
* Construct the analog filter transfer functions to meet those specifications.
* Use the bilinear transform to convert the resultant analog filter into a digital filter.

## The Inverse Bilinear Transform

The inverse bilinear transform can be specified as such:
    $z={\frac {1+{\frac {s}{2*f_{s}}}}{1-{\frac {s}{2*f_{s}}}}}$
Where $f_{s}$ is the sample rate $(f_{s}={\frac {1}{T}})$
This can also be written as:
    $z^{-1}={\frac {1-{\frac {T*s}{2}}}{1+{\frac {T*s}{2}}}}$
which very much resembles the Bilinear Transform.