# Feedback Control: Unexpected result for block diagram simplifications using matlab

I made some simple calculations regarding block diagram algebra. The problem is that I don't get the same result using matlab.

Here is the system with it's corresponding blocks:

$$H_1 = z+2$$ $$H_2 = \frac{1}{z^2+2z+1}$$ $$H_3 = \frac{z}{z+2}$$

This simplifies to the following according to the block diagram rules:

$$H = \frac{H_1*H_2}{1-H_1*H_2*H_3}$$

After some simple math I get:

$$H = \frac{\frac{z+2}{z^2+2z+1}}{1 - \frac{z+2}{z^2+2z+1}*\frac{z}{z+2}} = \frac{\frac{z+2}{z^2+2z+1}}{\frac{z^2+2z+1-z}{z^2+2z+1}} = \frac{z+2}{z^2+z+1}$$

Now if I try to get the same result using matlab it results in a system of order 5 and a system of order 3 after reducing it using matlab's minreal command:

% initialization
z = tf('z',0.1);
H1 = z+2;
H2 = 1/(z^2+2*z+1);
H3 = z/(z+2);

H_ = (H1*H2)/(1-H1*H2*H3)
H_ =

z^4 + 6 z^3 + 13 z^2 + 12 z + 4
---------------------------------------
z^5 + 5 z^4 + 10 z^3 + 11 z^2 + 7 z + 2

Sample time: 0.1 seconds
Discrete-time transfer function.

H_ = minreal(H_)
H_ =

z^2 + 4 z + 4
---------------------
z^3 + 3 z^2 + 3 z + 2

Sample time: 0.1 seconds
Discrete-time transfer function.


Only using Matlab's built in feedback command yields the correct result after evaluating minreal:

% calculate system transfer function using matlab's feedback command
H = feedback(H1*H2,-H3)
H =

z^2 + 4 z + 4
---------------------
z^3 + 3 z^2 + 3 z + 2

Sample time: 0.1 seconds
Discrete-time transfer function.

%
H = minreal(H)
H =

z + 2
-----------
z^2 + z + 1

Sample time: 0.1 seconds
Discrete-time transfer function.


Could you please guide me what I am doing wrong using the straight forward calculations for H_. Why do I get a system of order 3 after using minreal and not the same result as done by hand (or using feedback command)?

num = minreal(simplify(H1*H2))
den = minreal(simplify(1-H1*H2*H3))
H_nd = simplify(minreal(minreal(num/den)))

num =

z + 2
-------------
z^2 + 2 z + 1

Sample time: 0.1 seconds
Discrete-time transfer function.

den =

z^2 + z + 1
-------------
z^2 + 2 z + 1

Sample time: 0.1 seconds
Discrete-time transfer function.

H_nd =

z^3 + 4 z^2 + 5 z + 2
-----------------------------
z^4 + 3 z^3 + 4 z^2 + 3 z + 1

Sample time: 0.1 seconds
Discrete-time transfer function.

• (Z+2) has disappeared from the 2nd term of your analysis. Looks like you got the wrong factors for the 2nd order.
– Chu
Commented Jan 27, 2016 at 17:23
• Also, there are (z+2) factors that cancel in the 1st Matlab program.
– Chu
Commented Jan 27, 2016 at 17:28
• Sorry there was a mistake in my hand calculations. Now it is fixed and the same according to feedback command
– fjp
Commented Jan 27, 2016 at 17:41
• I still don't understand why H_ doesn't yield the same result
– fjp
Commented Jan 27, 2016 at 17:42
• It is the same - there are (z+2) factors in numerator and denominator that cancel. Perhaps you need to execute minreal a second time.
– Chu
Commented Jan 27, 2016 at 17:48

You need to add the tolerance to your minreal function.