Update Content - 2022-10-27
This commit is contained in:
@@ -35,6 +35,9 @@ There are several methods to go from the analog to the digital domain, `Tustin`
|
||||
|
||||
## Obtaining analytical formula of filter {#obtaining-analytical-formula-of-filter}
|
||||
|
||||
|
||||
### Procedure {#procedure}
|
||||
|
||||
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:
|
||||
@@ -56,13 +59,6 @@ First the symbolic variables are declared (`Ts` is the sampling time, `s` the La
|
||||
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
|
||||
@@ -70,6 +66,13 @@ Then the bi-linear transformation is performed to go from continuous to discrete
|
||||
s = 2/Ts*(z - 1)/(z + 1);
|
||||
```
|
||||
|
||||
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);
|
||||
```
|
||||
|
||||
Finally, the numerator and denominator coefficients can be extracted:
|
||||
|
||||
```matlab
|
||||
@@ -90,6 +93,126 @@ den = (Ts^2*wn^2 - 4*Ts*wn*xi + 4) + (2*Ts^2*wn^2 - 8) * z + (Ts^2*wn^2 + 4*Ts*w
|
||||
```
|
||||
|
||||
|
||||
### Second Order Low Pass Filter {#second-order-low-pass-filter}
|
||||
|
||||
Let's consider a second order low pass filter:
|
||||
|
||||
\begin{equation}
|
||||
G(s) = \frac{1}{1 + 2 \xi \frac{s}{\omega\_n} + \frac{s^2}{\omega\_n^2}}
|
||||
\end{equation}
|
||||
|
||||
with:
|
||||
|
||||
- \\(\omega\_n\\): Cut off frequency
|
||||
- \\(\xi\\): damping ratio
|
||||
|
||||
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 wn xi Ts s z
|
||||
```
|
||||
|
||||
Then the bi-linear transformation is performed to go from continuous to discrete:
|
||||
|
||||
```matlab
|
||||
%% Bilinear Transform
|
||||
s = 2/Ts*(z - 1)/(z + 1);
|
||||
```
|
||||
|
||||
The symbolic formula of the notch filter is defined:
|
||||
|
||||
```matlab
|
||||
%% Second Order Low Pass Filter - Symbolic representation
|
||||
Ga = 1/(1 + 2*xi*s/wn + s^2/wn^2);
|
||||
```
|
||||
|
||||
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
|
||||
gain = 1/(Ts^2*wn^2 + 4*Ts*wn*xi + 4)
|
||||
```
|
||||
|
||||
```text
|
||||
num = (Ts^2*wn^2) + (2*Ts^2*wn^2) * z^-1 + (Ts^2*wn^2) * z^-2
|
||||
```
|
||||
|
||||
```text
|
||||
den = 1 + (2*Ts^2*wn^2 - 8) * z^-1 + (Ts^2*wn^2 - 4*Ts*wn*xi + 4) * z^-2
|
||||
```
|
||||
|
||||
And the transfer function is equal to `gain * num/den`.
|
||||
|
||||
|
||||
### Second Order High Pass Filter {#second-order-high-pass-filter}
|
||||
|
||||
Let's consider a second order low pass filter:
|
||||
|
||||
\begin{equation}
|
||||
G(s) = \frac{1}{1 + 2 \xi \frac{s}{\omega\_n} + \frac{s^2}{\omega\_n^2}}
|
||||
\end{equation}
|
||||
|
||||
with:
|
||||
|
||||
- \\(\omega\_n\\): Cut off frequency
|
||||
- \\(\xi\\): damping ratio
|
||||
|
||||
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 wn xi Ts s z
|
||||
```
|
||||
|
||||
Then the bi-linear transformation is performed to go from continuous to discrete:
|
||||
|
||||
```matlab
|
||||
%% Bilinear Transform
|
||||
s = 2/Ts*(z - 1)/(z + 1);
|
||||
```
|
||||
|
||||
The symbolic formula of the notch filter is defined:
|
||||
|
||||
```matlab
|
||||
%% Second Order Low Pass Filter - Symbolic representation
|
||||
Ga = (s^2/wn^2)/(1 + 2*xi*s/wn + s^2/wn^2);
|
||||
```
|
||||
|
||||
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
|
||||
gain = 1/(Ts^2*wn^2 + 4*Ts*wn*xi + 4)
|
||||
```
|
||||
|
||||
```text
|
||||
num = (4) + (-8) * z^-1 + (4) * z^-2
|
||||
```
|
||||
|
||||
```text
|
||||
den = 1 + (2*Ts^2*wn^2 - 8) * z^-1 + (Ts^2*wn^2 - 4*Ts*wn*xi + 4) * z^-2
|
||||
```
|
||||
|
||||
And the transfer function is equal to `gain * num/den`.
|
||||
|
||||
|
||||
## 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.
|
||||
|
Reference in New Issue
Block a user