title: C Language Implementation for Proportional-Resonant Controller
date: 2018-06-22 18:50:40
tags: [Control, Power Electronics]
categories: Control
mathjax: true
---
First, let's see the transfer function of PR controller and its bode diagram :
\[
G_{PR}(s)=K_{p} + \frac{K_{r}s}{s^{2} + \omega_{r}^2}
\]
where the \(\omega_{r}\) is the resonant frequency.
As can be seen in the bode diagram, the gain at 50Hz (314 rad/s) is infinite, so PR controller can be used to track reference of specific frequency. However, the reference frequency is not always a constant, e.g. the frequency of electricity grid. In practice, Quasi-Proportional-Resonant can be used to solve this problem.
The transfer function of QPR and its bode diagram:
\[
G_{QPR}(s) = K_{p} +\frac{2 \omega_{i} Kr}{s^{2} + 2\omega_{i}s + \omega_{r}^{2}}
\]
where the addition of \(2\omega_{r}\) reduces the gain at resonant frequency but increase the band width around resonant frequency.
You can change the parameter \(\omega_{r}\) and run the demo code below to see how it changes the shape of bode diagram.
s = tf([1, 0], 1) ; Kp = 15 ; Kr = 2000 ; wr = 50 * 2 * pi ; wi = pi ; G_PR = Kp + Kr * s / (s^2 + wr^2) figure bode(G_PR) G_QPR = Kp + 2 * wi * Kr * s / (s^2 + 2 * wi * s + wr^2) figure bode(G_QPR)