# Discrete-Time Sliding Mode Filter with Adaptive Gain
## 3 Discrete-Time Sliding Mode Filter with Adaptive Gain  
This section presents a new model-free discrete-time sliding mode filter, which is an extension of PSMF. The presented filter is derived through a discretization scheme inspired by the principle of FOAW.  
The motivation for proposing a new filter comes from the following limitation of PSMF. That is, due to the fixed _acceleration_ gain \(F\), the output of PSMF cannot follow an input of which _acceleration_ exceeds that of PSMF, whereas the output becomes sensitive to the noise contained in the input of which _acceleration_ is far below that of PSMF. Towards this problem, the contribution of the presented filter is that its _acceleration_ gain \(F\) adaptively changes according to the motion of input to realize balance between the output smoothness and the suppression of delay.  
In order to achieve the above-mentioned balance, let us consider the following modification of PSMF. That is, for a rapid input motion, the value of \(F\) should be set large for instantly reflecting fast varying signals. On the other hand, for a slow motion, the value should be set small for obtaining smooth signals.  
The remaining problem is how to adaptively determine the value of \(F\) according to the motion of the input. Towards this problem, a modified adaptive method inspired by the principle of FOAW is applied. In the light of this idea, the algorithm of an extended PSMF, which is named parabolic sliding mode filter with adaptive gain (AG-PSMF), is obtained as follows:  
```
1:FOR \(n\in\{1,\cdots,\min(k+1,N_{\text{max}})\}\)
2:\(v:=(x_{1}(k-1)-x_{1}(k-n-1))/(nT)\)
3:FOR \(i\in\{1,\cdots,n\}\)
4:\(e:=x_{1}(k-i-1)-x_{1}(k-1)+iTv\)
5:IF \(|e|>R\); EXIT LOOP
6:END FOR
7:IF \(i<n\); EXIT LOOP
8:END FOR
9:\(F^{*}=\dfrac{N_{\text{c}}}{n}F\)
10:\(x_{2}^{*}:=F^{*}T\Phi\Big{(}\dfrac{u(k)-x_{1}(k-1)}{F^{*}T^{2}}\Big{)}\)
11:\(x_{2}(k):=\text{clip}(\text{clip}(x_{2}(k-1)-HF^{*}T,x_{2}(k-1)-F^{*}T,0),\)
12:\(\text{clip}(x_{2}(k-1)+F^{*}T,x_{2}(k-1)+F^{*}TH,0),x_{2}^{*})\)
13:\(x_{1}(k):=x_{1}(k-1)+Tx_{2}(k)\)
14:RETURN\(x_{1}(k)\),
```  
**Algorithm 3** AG-PSMF  
where \(N_{\text{c}}>0\) is a parameter. In AG-PSMF, a modification of FOAW determines the window size through the process of steps 1-8. It should be noted here that AG-PSMF uses the previous outputs for windowing, as shown in Figures 6 and 7, while FOAW employs the current and previous inputs, as described in Section 2.2. Then, in step 9, \(F^{*}(k)\) is obtained by applying the adaptively determined window size for balancing the tradeoff, the output smoothness and the suppression of delay. After that, in step 10, \(x_{2}^{*}(k)\) is determined under the constraint of \(F^{*}(k)\), and in step 11, \(x_{2}(k)\) is determined in order to follow \(x_{2}^{*}(k)\). Finally, in step 12, \(x_{1}(k)\) is obtained by integrating \(x_{2}(k)\).  
Figure 8 shows the behaviors of AG-PSMF and PSMF for the following input with step changes:  
\[u=\begin{cases}5&\text{if }t\leq 2\text{ s},\\ 10&\text{if }2\text{ s}<t\leq 4\text{ s},\\ -5&\text{otherwise}.\end{cases} \tag{7}\]  
In this case, it is shown that the convergence of AG-PSMF is faster than that of PSMF. This is because the adaptively changing gain \(F^{*}(k)\) of AG-PSMF adjusts the shape of sliding surface according to current input and system states.  
Figure 6: Block diagram of AG-PSMF.  
Figure 7: Windowing in AG-PSMF.