## 3 Learning Controller Design Using Fourier Series
Finally, in the \(k\)-th instant, the controller output is calculated as follows:  
\[u(k)=\sum_{n=0}^{N/2}\left(a_{n}^{k}\text{cos}\left(\frac{2\pi\text{ }n(N-1)}{N}\right)+b_{n}^{k}\text{sin}\left(\frac{2\pi\text{ }n(N-1)}{N}\right)\right) \tag{23}\]  
where:  
\[X_{n}^{k}=\sum_{j=0}^{N-1}w_{j}^{k}e^{-i\frac{2\pi nj}{N}},\quad\quad\quad n=0,1,...,N-1 \tag{15}\]0  
\[X_{n}^{k}=\sum_{j=0}^{N-1}w_{j}^{k}e^{-i\frac{2\pi nj}{N}},\quad\quad\quad n=0,1,...,N-1 \tag{15}\]1  
where \(\alpha_{n}\) is a gain used to obtain a proportion of the harmonics of the error dynamics. The coefficients \(\hat{a}_{n}^{k}\) and \(\hat{b}_{n}^{k}\) will be provided by a learning function, and these coefficients are designed to assure that \(p_{n}^{k}\) and \(q_{n}^{k}\) decrease. However, the main controller coefficients \(a_{n}^{k}\) and \(b_{n}^{k}\) must keep a value different from zero to produce a control signal for the system. Then, coefficients \(\hat{a}_{n}^{k}\) and \(\hat{b}_{n}^{k}\) perform the integral part equivalent in a PID controller. In the frequency domain, the integral part must adjust each coefficient of the main controller, until they converge to the correct values. Using the update law proposed by [16], coefficients \(\hat{a}_{n}^{k}\) and \(\hat{b}_{n}^{k}\) are calculated as follows:  
\[X_{n}^{k}=\sum_{j=0}^{N-1}w_{j}^{k}e^{-i\frac{2\pi nj}{N}},\quad\quad\quad n=0,1,...,N-1 \tag{15}\]2  
\[X_{n}^{k}=\sum_{j=0}^{N-1}w_{j}^{k}e^{-i\frac{2\pi nj}{N}},\quad\quad\quad n=0,1,...,N-1 \tag{15}\]3  
where \(\gamma_{n}\) is a learning gain for each harmonic and should be selected according to some conditions that will be shown in the next section to assure the convergence of \(p_{n}^{k}\) and \(q_{n}^{k}\). Note that the convergence of coefficients \(p_{n}^{k}\) and \(q_{n}^{k}\) to zero means that the coefficients \(\hat{a}_{n}^{k}\) and \(\hat{b}_{n}^{k}\) also converge to some value. Note that control law (23) was obtained through the IDFT when the harmonics of the \(s(t)\) were modified. However, from IDFT, in each sample period, a data window with \(N\) values is obtained. The control output is one value of that window. Due to the arrangement of data window \(w_{j}^{k}\), the control law in the \(k\)-th instant is \(j=N-1\), and for this reason, the control law given by (23) is calculated only with \(j=N-1\); other values of this window are not necessary. Before the control method begins, the initial conditions for window \(w_{j}^{k}\) and gains \(\alpha_{n}\) and \(\gamma_{n}\) are given. When the experiment starts, a sample of \(s(t)\) is taken, and \(w_{j}^{k}\) is updated. Later, the coefficients \(p_{n}^{k}\) and \(q_{n}^{k}\) are calculated through Equations (18), (19), (20) and (21) followed by the coefficients of the controller \(a_{n}^{k}\) and \(b_{n}^{k}\) with Equations (24) and (25). Finally, the control law is calculated from Equation (23), and the algorithm is repeated by taking another sample of \(s(t)\). In each cycle of the algorithm, a new data window \(w_{j}^{k}\) is obtained, and a new DFT is calculated. Then, it is necessary to restart the summations of the DFT. However, the summations of the learning part are not restarted, because the coefficients \(\hat{a}_{n}^{k}\) and \(\hat{b}_{n}^{k}\) have the information accumulated during the experiment. In this way, the controller has the information of the error dynamics, and also, it keeps the information of the learning part.