*This article is also published onÂ **Towards Data Science Blog**.*

**Table of Content**

Have you ever wondered why when you turn the hot water knob on in the shower, the water will be cold for a few seconds, and then it gets hot or vice versa?

In this article, we are going to answer this question by touching upon two concepts, namely theÂ Minimum PhaseÂ (MP) systems, andÂ Transfer Functions.

**Introduction**

Let me first elaborate on the question. The phenomenon I mentioned in the question is particularly noticeable in climates, where water supplies are different than the ambient temperature. I lived in both extreme climates. In a hot country where the temperature reaches 45Â° Celcius (113Â° Fahrenheit) in summer if you turn the cold water knob, the water supply is first super hot, and then after some time, it gets colder. On the other hand, Iâm currently living in a city wherein winter, the temperature reaches -20Â° Celcius (-13Â° Fahrenheit), and even less. If you turn the hot water knob, it takes a few seconds for the water supply to get hot. Both phenomena follow a similar behavior from a control engineering perspective.

This article will answer this question from a control system theory perspective. The short answer is that because the water supply system in the shower is aÂ non-minimum phase (NMP) system.

To get a better understanding of how an NMP system behaves, letâs work on an example. We are going to need a mathematical model for our system. Since NMP can be better understood using theÂ transfer functionÂ model, we need to be aware of this concept. However because this representation is less common than other mathematical models like differential equations, letâs first briefly go over what the transfer function is and how a model can be represented in this way. If you are already aware of what a transfer function is, then feel free to jump to the example.

**Transfer Function**

There are several ways to represent a physical systemâs mathematical model, such asÂ differential equations,Â state-space representation, andÂ transfer function. Most commonly, we use time-based functions to model our physical systems using the first two approaches mentioned (just to be clear we can write differential equations of a model in frequency domain but itâs less common in mathematical modeling of physical systems). However, a transfer function provides us with another way of looking at a system by analyzing the system in the frequency domain. Now, letâs see what a transfer function is!

**What is the Transfer Function?**

A transfer function model describes an input-output relationship of a system using a ratio of polynomials. So, an input signal is given to a system to produce a controlled output (aka response). This type of modeling is different than using differential equations and state-space representations where the model dynamics is available.

A transfer function is another way of viewing a dynamical system but in the frequency domain by analyzing the system response for a given input signal.

The transfer function of a control system is the ratio of the Laplace transforms of output signals over the Laplace transform of the input signal. In a nutshell, instead of analyzing a model in the time-domain using time-based differential equations, the goal here is to analyze the model in the frequency-domain using a transformation.

So, letâs say we have a system withÂ Â andÂ Â as our input and output signals. The transfer function can be calculated as shown above.

The roots of the numerator polynomial are called the modelÂ *zeros*, and the roots of the denominator polynomials are called the modelÂ *poles*. The zeros affect the input to a system, and the poles affect the system response and its stability. For zero-pole analysis, we should use the *s*âplaneÂ that is a complex plane on which Laplace transforms are graphed[1].

In this article, we are only interested in the initial response of the system in order to answer the question of why the shower first gets cold before it gets hot? Since theÂ initial system responseÂ is closely related to system zeros as noted earlier, therefore, we will not talk about the poles (perhaps that can be a topic for another article).

**What are Non-Minimum Phase Systems?**

Now that we are familiar with an NMP system, letâs define the system formally:

Having a delay in our system or a model zero on the right half of theÂ *s*âplaneÂ (aka Right-Half Plane or RHP) may lead to a non-minimum phase system.

Note that there is only one minimum phase system for a given magnitude response, but there is an infinite number of NMP systems. This is the reason why we do not hear a term like the maximum phase system. More detail about non-minimum phase systems with mathematical description is available in [3].

**Case Study**

Now that we are familiar with Transfer Functions, letâs see how a non-minimum phase system will look like and answer why we water will first get colder before it gets hot!

Below are two systems that have the same poles but with different zeros. System 1 has a zero atÂ , whereas System 2 has a zero atÂ .

Letâs separate poles and zeros of System 1 for our analysis. As noted earlier, you can think of the zero as a modified input letâs call it . As noted earlier, we are interested in the model zeros in this article, so we will focus on the green block.

Letâs see how the modified input of System 1 is in the time-domain by applying an inverse transform

Following the same procedure for System 2, the modified input for System 2 will be

So, the only difference is in that negative sign. Letâs plot the input and the modified input signals for both systems and see how both differ.

Letâs use theÂ unit stepÂ as our input signalÂ Â (the gray function on the top). Since the input signal is a unit step, the outputÂ Â is referred to as theÂ step response. The modified inputÂ Â is illustrated bellow that is the summation ofÂ Â and a derivative ofÂ . The derivative component ofÂ Â is blue for System 1 and red for System 2.

The negative derivative of in System 2 causes the step response of System 2 to go first towards the opposite direction of the expected response (steady-state value) before moving towards the expected response (the red curve). This is in contrast to the step response of System 1 (blue curve) that does not have this undershoot at the beginning.

A nice illustration is available in Ref. [4].

So, the next question is what to do when we have a non-minimum phase system?

The solution is to just wait âł. We have to wait until the undershoot is over. We can also design a controller/compensator for such systems. However, designing a controller is harder for NMP systems for several reasons like the risk of the system getting unstable or having a slower response.

Now, letâs get back to our question in the beginning. Why the water in the shower is cold first when you open the hot water supply before getting hot?

The answer is that when you open the hot water supply in showers, the system experiences an undershoot since itâs a non-minimum phase before the water gets hot. In this case, itâs better to wait a few seconds so that the system recovers (from the undershoot). You should not change the direction or open the other knob since that will end up in a colder shower in the long-run!

Another example that is usually used in Control System books is the aircraft altitude change in response to elevator deflection. In this case, when the aircraft tries to increases its altitude using elevator, the altitude slightly decreases due to the aircraft tailing down (resulting in a downward aerodynamic force) before it increases its altitude. This example is available with the mathematical model in Chapter 6 of the book âFeedback Control of Dynamic Systemsâ by Franklin (7th edition) [5].

# Conclusion

In this article, we learned about what a non-minimum phase system is and why such a system first experiences response in the wrong direction (you turn the hot water knob, and the water is first cold!). We also talked about the transfer function and how it can be useful in analyzing systems.

The Jupyter notebook containing the code used to create the step responses for the case study is available on GitHub.

**Thanks for reading đ**

*If you liked this post, you can join my mailing list to receive similar posts. You can follow me on **LinkedIn**, **GitHub**, **Twitter** and **Medium**.*

*And finally, you can find my knowledge forest đ˛ (raw digital notes) at **notes.ealizadeh.com**.*

**đŠ Join my mailing list**

# References

[1] MATLAB. (2020, October 25).Â *What are Transfer Function Models?*Â Retrieved fromÂ https://www.mathworks.com/help/ident/ug/what-are-transfer-function-models.html

[2] Wikipedia. 2020.Â *Minimum phase*. Last modified August 8, 2020,Â https://en.wikipedia.org/wiki/Minimum_phase

[3] Jesse B. Hoagg & Dennis S. Bernstein, Nonminimum-Phase Zeros â Much To Do About Nothing (Classical Control Revisited â Part II), June 2007, IEEE Control Systems Magazine (AvailableÂ here)

[4] MATLAB. (2019, December 9).Â *Control Systems in Practice, Part 6: What Are Non-Minimum Phase Systems?*Â YouTube.Â https://www.youtube.com/watch?v=jGEkmDRsq_M

[5] G. F. Franklin, J. D. Powell, A. Emami-Naeini,Â *Feedback Control of Dynamic Systems*, Seventh Edition

âŹ
ď¸ **Previous Post **

**Copyright ÂŠ 2021 Esmaeil Alizadeh - All Rights Reserved**