Update Content - 2022-08-24
This commit is contained in:
@@ -8,6 +8,100 @@ Tags
|
||||
: [Digital Filters]({{< relref "digital_filters.md" >}})
|
||||
|
||||
|
||||
## Continuous to discrete transfer function {#continuous-to-discrete-transfer-function}
|
||||
|
||||
In order to convert an analog filter (Laplace domain) to a digital filter (z-domain), the `c2d` command can be used ([doc](https://fr.mathworks.com/help/control/ref/lti.c2d.html)).
|
||||
|
||||
<div class="exampl">
|
||||
|
||||
Let's define a simple first order low pass filter in the Laplace domain:
|
||||
|
||||
```matlab
|
||||
s = tf('s');
|
||||
G = 1/(1 + s/(2*pi*10));
|
||||
```
|
||||
|
||||
To obtain the equivalent digital filter:
|
||||
|
||||
```matlab
|
||||
Ts = 1e-3; % Sampling Time [s]
|
||||
Gz = c2d(G, Ts, 'tustin');
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
There are several methods to go from the analog to the digital domain, `Tustin` is the one I use the most as it ensures the stability of the digital filter provided that the analog filter is stable.
|
||||
|
||||
|
||||
## Obtaining analytical formula of filter {#obtaining-analytical-formula-of-filter}
|
||||
|
||||
The Matlab [Symbolic Toolbox](https://fr.mathworks.com/help/symbolic/) can be used to obtain analytical formula for discrete transfer functions.
|
||||
|
||||
Let's consider a notch filter:
|
||||
|
||||
\begin{equation}
|
||||
G(s) = \frac{s^2 + 2 g\_c \xi \omega\_n s + \omega\_n^2}{s^2 + 2 \xi \omega\_n s + \omega\_n^2}
|
||||
\end{equation}
|
||||
|
||||
with:
|
||||
|
||||
- \\(\omega\_n\\): frequency of the notch
|
||||
- \\(g\_c\\): gain at the notch frequency
|
||||
- \\(\xi\\): damping ratio (notch width)
|
||||
|
||||
First the symbolic variables are declared (`Ts` is the sampling time, `s` the Laplace variable and `z` the "z-transform" variable).
|
||||
|
||||
```matlab
|
||||
%% Declaration of the symbolic variables
|
||||
syms gc wn xi Ts s z
|
||||
```
|
||||
|
||||
The symbolic formula of the notch filter is defined:
|
||||
|
||||
```matlab
|
||||
%% Notch Filter - Symbolic representation
|
||||
Ga = (s^2 + 2*xi*gc*s*wn + wn^2)/(s^2 + 2*xi*s*wn + wn^2);
|
||||
```
|
||||
|
||||
Then the bi-linear transformation is performed to go from continuous to discrete:
|
||||
|
||||
```matlab
|
||||
%% Bilinear Transform
|
||||
s = 2/Ts*(z - 1)/(z + 1);
|
||||
```
|
||||
|
||||
Finally, the numerator and denominator coefficients can be extracted:
|
||||
|
||||
```matlab
|
||||
%% Get numerator and denominator
|
||||
[N,D] = numden(Ga);
|
||||
|
||||
%% Extract coefficients (from z^0 to z^n)
|
||||
num = coeffs(N, z);
|
||||
den = coeffs(D, z);
|
||||
```
|
||||
|
||||
```text
|
||||
num = (Ts^2*wn^2 - 4*Ts*gc*wn*xi + 4) + (2*Ts^2*wn^2 - 8) * z + (Ts^2*wn^2 + 4*Ts*gc*wn*xi + 4) * z^2
|
||||
```
|
||||
|
||||
```text
|
||||
den = (Ts^2*wn^2 - 4*Ts*wn*xi + 4) + (2*Ts^2*wn^2 - 8) * z + (Ts^2*wn^2 + 4*Ts*wn*xi + 4) * z^2
|
||||
```
|
||||
|
||||
|
||||
## Variable Discrete Filter {#variable-discrete-filter}
|
||||
|
||||
Once the analytical formula of a discrete transfer function is obtained, it is possible to vary some parameters in real time.
|
||||
|
||||
This is easily done in Simulink (see Figure [1](#figure--fig:variable-controller-simulink)) where a `Discrete Varying Transfer Function` block is used.
|
||||
The coefficients are simply computed with a Matlab function.
|
||||
|
||||
<a id="figure--fig:variable-controller-simulink"></a>
|
||||
|
||||
{{< figure src="/ox-hugo/variable_controller_simulink.png" caption="<span class=\"figure-number\">Figure 1: </span>Variable Discrete Filter in Simulink" >}}
|
||||
|
||||
|
||||
## Typical Transfer functions {#typical-transfer-functions}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user