# Controls: Getting the feedback transfer function of a Plant and Controller

I'm designing a function in Python similar to MATLAB's 'feedback(T)' command. I know modules already exist, but it's something I want to do for myself for fun. However, I am running into issues. Let's say I have the transfer function of some arbitrary plant $$T(s) = {s + 5\over s^2 + 4s + 7}$$ Let's also say I have some arbitrary PID/PI/PD controller (Not to imply this controller is actually good, this is more to demonstrate the concept, so keep that in mind!)

$$C(s) ={2.3802s + 7.7309 \over s}$$

We know that the Closed Loop Feedback Transfer Function has the form of $$CLTF ={T(s)C(s) \over 1 + T(s)C(s)}$$

When CLTF computed above in Matlab, we get ... $$CLTF = {2.38 s^5 + 29.15 s^4 + 133.8 s^3 + 292 s^2 + 270.6 s\over s^6 + 10.38 s^5 + 59.15 s^4 + 189.8 s^3 + 341 s^2 + 270.6 s}$$

However, using MATLAB and feedback(T*C,1), we get the result of ... $$2.38 s^2 + 19.63 s + 38.65 \over s^3 + 6.38 s^2 + 26.63 s + 38.65$$

I already realize I can take my CLTF in MATLAB, put it in pole/zero (zpk) and things will cancel to get the same result as MATLAB's feedback command. However, no symbolic program seems to be able to factor these polynomials. MATLAB is clearly doing something I don't know about then. Does anyone have a clue how matlab's algorithm works? Or how I could code this same function?

• Have you considered that MATLAB make factorize before multiplying T(s) and C(s)? – Andy aka Dec 14 '15 at 21:10
• Well that is the issue. I do realize MATLAB can do it, you can take my CLTF and stick it into the zpk() function, and it will factor it for you (and things cancel out leading to matlabs CLTF). However, no symbolic processor seems to be able to factor those polynomials except for matlab's zpk. Also, the other issue is I'm coding this in Python, so just using another matlab function kind of makes the point moot, since I'm just convolving the polynomials in python to get the result, since it doesn't have symbolic processing like matlab. I need a way to get the same matlab result. – Collaptic Dec 14 '15 at 21:25

It depends how the calculation is done. Take as an example $\small G= \large \frac{1}{s+a}$, and $\small K= 1$. We may write the CLTF as:

$$\small\frac{G}{1+GK}=G.\frac{1}{1+GK}=\frac{1}{s+a}.\frac{1}{\left(1+\frac{1}{s+a}\right)}=\frac{1}{s+a}.\frac{s+a}{(s+a+1)}$$

This expands to:

$\large\frac{G}{1+GK}=\frac{s+a}{s^2+(2a+1)s+(a^2+a)}$

which is correct but inconvenient, and which reduces to:

$\large \frac{G}{1+GK}=\frac{1}{s+(a+1)}$ when the $(s+a)$ factor is cancelled.

To force the reduce form, you could try writing $\small G$ and $\small K$ in numerator/denominator form: $\small G=\large \frac{N_g}{D_g};\:\:\:\:\small K=\large\frac{N_k}{D_k}$, then write the CLTF as:

$$\small\frac{G}{1+GK}=\frac{N_g\:D_k}{D_g\:D_k+N_g\:N_k}$$

Note that Mathworks recommends using the FEEDBACK command to derive closed-loop TFs, as this gives the reduced form.

• Thanks. This helps...slightly. I already know mathworks recommends the feedback command, I use the feedback command. However, I'm programming the feedback command in python. It still doesn't explain how it works. I need to know how to get to that reduced form from expanded out CLTF in polynomial form from the plant and controller (TC/(1+TC) like I have in my post. – Collaptic Dec 14 '15 at 21:56
• I guess what I'm getting at also is, is (TC/(1+TC)) the correct CLTF form for a controller and plant? Because I want to step the response to see how the controller effects the the response. If (TC/(1+TC)) is the same thing as the feedback(T*C,1) in matlab, I should get the same step response, but I do not in this case. – Collaptic Dec 14 '15 at 22:01
• Express $G$ and $K$ as $\dfrac{N_g}{D_g}$ and $\dfrac{N_k}{D_k}$; then $\dfrac{G}{1+GK}= \dfrac{N_gD_k}{D_gD_k\:+\:N_gN_k}$ – Chu Dec 14 '15 at 22:09
• Just to clarify, Ng/Dg, Nk/Dk are the numerator and denominator of G, and K. Correct? If so, I'll give it a go. Thanks for your help – Collaptic Dec 14 '15 at 22:12
• Yes. Good luck! – Chu Dec 14 '15 at 22:13