 So I am looking at SOS single output systems and I am trying to design a Leuenberger observer so there is only one measurement okay idea was to come up with a observer gain L such that poles of this matrix poles of this matrix Phi-LC are a desired location this problem is called as pole placement problem and this was solved first time by Leuenberger sometime in nineteen sixty for sixty four or sixty two for a single input single output system and later he extended it to multiple input multiple output systems we are not going to look at the multiple input multiple output case I am going to describe something else for multiple output multiple input systems but conceptually this actually marks a landmark because you are trying to decide how passed or how slowly should the poles of the error dynamics how dynamics of error should evolve by choosing the poles by locating the poles in a desired location. Now there is a compromise to be stuck here because if you choose the poles very close to zero the error will decay very fast but then your observer will become sensitive to noise okay right now we are not taking into consideration noise in any way okay we and if you place it close to one the error dynamics will be slow okay so it will slowly converge to zero it will not be so sensitive to noise but it will slowly converge to zero so there is a balance to be struck and how do you choose poles to strike this balance is not an easy task okay so one needs to look at some other ways of solving this problem nevertheless it is an important landmark development and there are many developments after that which actually can be viewed as extensions of these ideas so this is one of the so when there are stochastic disturbances this Lienberger observer might give you suboptimal behavior suboptimal you know performance but then it depends upon the viewpoint the way you want to design your controller or observer so I am not saying that one should not go by this approach this is one very nice way of designing an observer and if you get comfortable if you start getting feel of how to place poles to get good disturbance injection then you can use this course okay so just a quick overview of what we have done we did a transformation from the original state space to a new state space this is the power of you know doing everything in state space you can just reorient your state space do a design in the oriented state space and come back okay so that is qualitatively similar to many times what we do in Laplace transform we go from time domain to Laplace domain do some manipulations there come back and come up with a solution in time domain so philosophically you can look at this is the same thing you are transforming from one state space representation to another state space representation which is convenient what is what does not change when you reorient the state space the transfer function between input and output does not change that is very important okay so you do this transformation to this observable canonical form we already know how to arrive at the observable canonical form in some different context so you transform in the transform coordinate you do a design you place the poles to the desired location and then recover the observer gain matrix in the original domain so the transformed system looks like this and together with the observer the poles of this Phi O-LoCO or LACA so these roots of the characteristic equation which appears in the first column so just looking at the observable canonical form is advantage looking at the first column you can tell what is the characteristic equation so if you choose a specific characteristic equation then you can just map the coefficient you can just equate the coefficient and then come up with a design in the transform domain okay so this is what you would get if you were to use an observer you want this characteristic equation to be equal to this equation just equate the poles just equate the coefficients once you equate the coefficients see what is known to you here you are specifying this polynomial so you know this you are specifying this polynomial you have chosen certain roots of the closed loop that will give rise to this polynomial so you know the coefficients here you know A1 to An you do not know L1 to Ln that just can be found by equating the coefficients this is the characteristic polynomial of the closed loop with the observer this is the desired characteristic polynomial you just equate and you will get L0 once you get L0 you just use the inverse transformation and come back to the original state space so you got L0 in the transform space you get L in the original space just by doing inverse transformation which is T inverse and how do you get this T matrix this T matrix is nothing but you know it is obtained by multiplication of observability matrices inverse of the transform matrix into observability matrix of the original system both of these are known because the special form of the transform system you know this by the way we are talking about single output system so the observability matrix here is a square matrix okay single output system the observability matrix will be n x n okay if it is system is observable the rank is equal to n otherwise the system is not observable okay so this actually expression tells you that you can place the poles at whatever location you want provided the system is observable the system is not observable this T matrix cannot be computed okay so rank of the observability matrix is very very crucial okay it is very very crucial because T has to exist and T inverse also has to exist so for T inverse to exist this matrix observability matrix of the original system should be invertible right see both of them are n x n matrices okay this is this T is given by this this multiplication of these two matrices T inverse will involve inverse of observability matrix that is possible only when rank is equal to n okay only when rank is equal to n so okay and then I just showed you a specific example where we took this CSTR the reactor example where we have two states concentration and temperature I am only measuring temperature so y is equal to only 0 1 x we have seen that this system is observable so I can place the poles wherever I want okay if I do a canonical transformation the observable canonical form will look like this this is the these are the coefficients of the characteristic equation which appear in the first column and then if you do a design you get this L0 which is for well why I am calling this LP right now will become clear soon but the observer you know equation comes out to be just T inverse into where T inverse have shown you what is the T inverse can be computed very easily so this is how you design the observer and what is the effect this is a open loop simulations okay open loop observer no feedback okay model running in parallel to the plant same input given to the model and the plant okay only problem is the initial state is wrong okay initial state which is known to the observer is wrong the plant is somewhere else okay this plant is open loop stable okay observer error goes to 0 very slowly okay now so you can see here it takes about 5 minutes for the observer error to go to 0 whereas when I put this viewing burger observer even if I choose poles at 0.5 0.5 the observer error goes to 0 very quickly okay within 1 minute within 10 samples okay the time scale here are different please note this is 2 minutes whereas this is 5 minutes okay so this is expanded here in a very short time 0.5 minutes in 5 samples or 6 samples the error between the true and estimate goes to 0 when you are using the feedback gain okay so the observer does help you feedback correction does help you to quickly reduce the error to 0 okay this is the plots of the errors when both poles are placed at well we can check what happens the plant is linear simulation model is nonlinear simulation so all those things we can check the both of them are linear of course the error goes to 0 very fast if you take the realistic situation where the plant true plant is nonlinear simulation and you know my observer is living burger observer which is linear observer then also it works quite well it is not that as long as the range of as long as the operation range of your system is close to the point of linearization okay you are using a linear observer the plant is nonlinear they will behave like each other as long as you are close to the operating point where you are linearized okay the model and the plant become too different then this will not work but you can see here that I am only measuring temperature I am not measuring concentration okay I am plotting true versus estimated just for your reference in reality I am never going to know the true value I am going to only measure temperature okay but since you are doing computer simulations you can compare the true versus estimated okay and you can see that estimates are very very close to the truth so I can use this observer as a soft sensor see I want to control concentration okay so I can put now PID controller that takes concentration as a measurement you can give a concentration set point okay this is many lines called as inferential control that you are inferring concentration from temperature measurements through a model okay and then using it for further control right now we are not going to the control we are just talking about a software sensor where I get an estimate of concentration you know with and this is the error how error behaves error is pretty close to 0 so I just listed here some of the square of errors and they are pretty small so right now these numbers may not make much sense okay so now what we have designed right now is this observer okay now this is called as a prediction observer this is not there is one more way of designing observer I am going to talk about it now why am I calling it prediction that is because the state at K plus 1 has been estimated using measurement at point K okay or if you take K as the current point if you take K as the current point okay estimate at point K will be constructed using YK minus 1 okay there is one delay between the estimate and YK okay so now you might wonder why I put a delay if I am getting a measurement now okay I can correct the state at the current point time point you know I can correct the estimate generate an estimate which is corrected at the current so this is called as a prediction estimator and in contrast when I talk about now current state estimator the difference will become clear okay so there is one lag between the estimate and the measurement and sometimes you need to use this observer that is because you want to do very fast combinations you do not have time to you know when you get the measurement okay let us say I am doing I am writing an observer for induction motor okay now for induction motor the sampling time will be you know maybe 100 milliseconds something like 40 to 100 milliseconds I will take sampling time okay to do computations in 100 milliseconds depending upon what kind of microprocessor you are using it can be very very costly okay so what I can do in that case is that I get a measurement okay and then I can using the previous measurement I can keep an estimate ready when I at time point K between the two samples okay I can do the calculations I have some time to do calculations I can keep the prediction estimate ready and use it for control instead of calculating estimate at that point and using it immediately okay I may not have time to do computations but if your system is low then you do not have to use this estimator you can do something better okay so what is that what is that thing current state estimator is we modify the prediction step like this okay I do a prediction okay I do a prediction then the situation where you are not able to use this current state estimator and you have to use prediction estimator are kind of disappearing because computing is becoming faster and faster okay so that is somewhat you can say in many situations not quite relevant now so I do a prediction so what I am doing here what I am doing here is this is my previous estimate now this understand a notation X hat is estimate of X okay K-1 means it is at time instant K-1 okay using information up to K-1 using measurements up to K-1 that is the notation here okay so right now before the measurement has arrived I can do this computation of X hat K given K-1 it means I can do a prediction of the current state okay using the previous information that is previous information is this and the input that has gone at time K-1 okay so this is the prediction step and then I can do a correction there is a error here just correct your notes okay so and what I do then is what I do then is then do a update here okay I have this I have this prediction of X using information up to K-1 okay I can use that to predict Y C times X hat K given K-1 is prediction of Y what is this quantity this is quantity this quantity is prediction of Y using the state predicted state okay this is my predicted state this is prediction of Y see because my model is Y is equal to C of X right so I can predict Y using information up to K-1 that is this difference YK- YK- is the error prediction error it is also called as innovation okay and this gain observer gain times this error is added to this prediction okay I do a correction so what I am doing is here those of you who are familiar with numerical methods prediction correction algorithms okay for integration you do a prediction using explicit method you do a correction using implicit method okay so somewhat similar philosophy prediction correction okay so you do a prediction using model and then you fuse data with the model see what is happening here Y is the real data this calculation is happening in my computer I am running the model parallel to the plant the input which is given to the plant is given to the model okay I did a prediction of what is the expected value of Y based on what I know from the past that you can get from this model okay this difference will tell you okay what is actually Y that you got this Y here is the true measurement which is coming from the plant okay this difference is the error between estimated Y and a true Y okay and this error is used to correct the state okay what I want is that the model should be in sync with the plant and this is done through the correction okay this is done through the feedback correction so LC is the feedback again and if you do a little bit of calculations you can see that the error dynamics get slightly modified now okay you can just do this algebra it is very very simple to do this algebra we just take the truth and estimate and the subtract truth and estimate and then you can derive this equation just like we did earlier for prediction case you can do this here and obviously the what is the criteria the criteria is that poles of this matrix ? into I-LC okay I am calling this LC here okay I am calling this matrix LC here because this is current state estimator okay so see here X hat K okay is estimate of K using measurements up to time K okay because I have used YK to estimate XK okay whereas this contrast this with the previous one look here there is a delay here between the delay here between estimate and Y see this is for K-1 you are using YK so at K you will be using YK-1 if you use the same equation same difference equation if you want to estimate X hat K given K-1 you will be using here YK-1 okay so there is a difference between this prediction estimator and current state estimator okay so the error dynamics is slightly different and then you can do pole placement and you can do all kinds of things here you can show what is the relationship between so the earlier one earlier gain I have called LP that is for prediction gain this LC stands for current state estimator gain okay so that is subtle difference between the two and they are related through this relationship provided ? is of course invertible okay ? is not invertible there is a problem but if ? is invertible these two are related through this equation prediction estimator prediction estimator I would use actually see you know you want to let us say you are doing control of concentration based on temperature measurement okay and see this is my current type okay so this is future and this is past K is my current time okay now see I am going to get a measurement here which is YK-1 I am going to get a measurement here YK okay now there is a time gap between this see there is this time gap is my sampling interval okay now see using YK-1 I can predict using this YK-1 I can predict here X hat K K-1 I can okay so I can predict X hat K given K-1 and if I have this prediction then using this I can create Y hat K given K-1 okay so then what I can do is to let us say I am implementing a PID controller okay I can use this Y hat without waiting for measurement to take place okay see because I can use this Y hat or I can use this X hat for my control see suppose I am only measuring temperature okay and I want to control concentration in my PID controller so I need this X hat okay so I have this X hat available with me using the measurement which was obtained at K-1 okay when you do this calculations I have time to do the calculations in this gap okay and I am ready with the concentration estimate here okay so without waiting for YK okay without waiting for doing observer calculations I just use this concentration estimate and do control I collect the measurement but do not do calculations then I can do calculations in between here and then in between here and I can compute X hat K-1 given K okay and as a new instant I will get another measurement here which is YK-1 but I have this estimate so I will use the estimate for control okay when you will do this you know when you know the time required the time gap see if you know you do not have too much time to do computations if your system is very very fast okay then I will do some calculations in the inter sample period keep it ready and use it okay so that is the advantage of using prediction estimate okay now see this you will not realize unless you face a situation where the computation time is so small or the gap between two sampling intervals is so small that you know you are not able to do computations but between see between two samples what you do you have time to do computations right so I can keep some background computations which is you know doing this see this calculation this calculation can go in the background between the two samples when I have YK-1 I can use it to estimate X hat K given K-1 okay and at instant K without waiting for the measurement to come do observer calculations I just use the estimated predicted value and do control okay now here you are saying that after the measurement arrives at instant K you are first doing the observer calculations okay and then then the observer then I will use this estimate for control you see the difference you are still not getting it okay see now put see this these two steps okay might require some you know some 20 milliseconds if you do not have those 20 milliseconds see suppose your sampling interval is 50 milliseconds if you spend 20 milliseconds in doing calculations for observer okay then you know there is a problem you should instantaneously do your calculations that is what is expected when you do digital control instantaneously means the time required for computations is very very small compared to the sampling interval if it is not okay then what you do is use the predicted value from the which you are generated between the two samples okay do control collect the measurement okay in between next two samples do again calculations keep it ready for the next sample so this is more of the implementation issue okay and then why am I still talking about prediction estimators when you can when you know computation times are becoming smaller and smaller will become clear towards the end of the lectures because I am going to connect these observers to a time series models which we have developed and I will show that the time series models that we have developed are nothing but prediction estimators so that is another reason why am it still introducing prediction estimators even though you know they might appear outdated okay now we did an ideal world design no measurement noise no unmeasure disturbances model is perfect and we said only possible error is in the initial state of the observer plant state is something initial state of the observer is something and we were worried about whether the you know estimate goes to the truth under the ideal conditions but the real world is not like this there are always measurements which are corrupted with noise you never get a perfect measurement okay you always have some kind of unknown input affecting the sensor measurement now we know how to do stochastic modeling right we know white noise we know colored noise we know all kinds of things so if I have a sensor okay I can try to develop a model for the noise I can try to develop a model which is a white noise or the colored noise typically sensor noise is a white noise okay you can if you do this experiment of taking a sensor keeping the true value of the plant constant and just collect data we will find that the noise the measurement is typically something like a white noise okay so we can develop a model how do you develop a model for the white noise mean and variance particularly if it is Gaussian white noise life is very easy Gaussian distribution is characterized by first two moments mean and variance so just characterize this find out mean and variance and you are done you have a model for how the noise behaves that means even if you do not know exactly what value the noise will take you know that it behaves like a white noise which is Gaussian distribution with mean equal to 0 expected value 0 okay standard deviation is so much so this you can you have a model okay you can construct a model for the noise okay then if you have a model for noise can you use it to improve your estimates that is the first question the problem is when if you do this modeling how do you choose a pole okay how do you do pole placement such that you know the noise is effectively rejected is very difficult question to answer okay the route that we have taken of pole placement okay is such that it does not what I will have to do if I have to actually develop an optimal gain which rejects the noise is to do trial and error you know try different values of poles and how many values of poles you can try infinite values of poles are there so how do you try there is no systematic way of you know choosing pole location such that the noise is rejected optimally so knowing the noise model does not help in you know placing the poles okay so you know how to model the noise you have something more now about the noise does not help you in placing the poles so you need some other method for there is also one more possibility that there are errors in the measurement okay there could be there could be unknown inputs influencing the dynamics right we assume that input is only you which is not true there could be something else okay which is influencing the dynamics I do not know and we have already seen that in time series modeling just effect of you does not explain everything that happens in why there is something else so there is some unknown input and then we need to model that unknown input okay so let us take let us go back to our good old linearization okay remember this continuous time model which we developed okay we had this model which is a xt plus bu t plus this is the disturbance term for a long time we never talked about it okay but now I am going to consider this disturbance term dt okay so this could be in real plant this could be some input which is actually entering the system which we are not measuring we do not have a control over it okay so for example if you just have a simple tank and you have flow coming in the flow may not be constant really fluctuating okay so the fluctuations in the inlet flow will be actually d here okay so many many situations you have inputs everything that affects the dynamics you cannot measure okay so you are the manipulated variables d are the inputs or disturbance inputs okay now in y in y effect of this d is going to be present okay whether you like it or you do not like it okay the effect of disturbances is there in y okay well of course we have this perturbation variables and we normally assume that the inputs the manipulated inputs of piecewise constant why do we assume that because we implement digital control or computer control through a zero order hold that is digital to unlock converter in which we hold the inputs with piecewise constant okay now there is a trouble here what about this guy dt that is not going through a zero order hold that is actually entering the system continuously it is changing continuously within a sampling period also it is changing okay I am going to make a simplifying assumption okay I am going to assume that the sampling period is small enough okay that so small that I can approximate this dt using piecewise constant functions okay so that is a simplifying assumption so just like the manipulated variables of piecewise constant I am going to assume that the inputs disturbance inputs okay are also or can be modeled as can be adequately represented as okay piecewise constant functions this does not mean they are actually entering as piecewise constant functions the disturbances which are entering real world disturbances which are entering are not entering piecewise constant manner it is a simplifying modeling assumption that we make to simplify the mathematics associated with it okay I am going to make one more further assumption right now because you know not only that these are piecewise constant I am going to assume it is like a white noise okay what if it is not a white noise we can solve that problem later let us take a you know idealized problem where the disturbances are entering as if they are a white noise piecewise constant white noise okay that is what is our assumption okay so it is a white noise zero mean Gaussian white noise let us assume Gaussian white noise so what do I need to know for characterizing Gaussian white noise mean and covariance okay when I mean and covariance I am done so I have a model for disturbances so this disturbances are entering as a zero mean white noise process with covariance equal to D well to do my algebra I do not need Gaussianity anywhere so right now I am not written anywhere Gaussianity I will come to Gaussianity little later okay I would be using Gaussianity at some other point so now I have this three simplifying assumptions just note them first simplifying assumption is that I am assuming that disturbances are piecewise constant okay or can be modeled as piecewise constant this is simplifying assumption one simplifying assumption two is that not only that piecewise constant they are like white noise with zero mean and known covariance I know the covariance I know the mean is zero okay I will worry about what if they are not white noise later okay there are ways to handle that we will look at it later my third assumption is that the measurements are corrupted with another white noise my measurements are corrupted with another white noise whose mean is zero and so this errors in the measurement are random okay I know their mean I know their variance typically this matrix are here will be a diagonal matrix if there are five measurements five sensors then this will be a diagonal matrix with all of diagonal elements equal to zero diagonal elements will be variances of each sensor okay error variance of each sensor that you can find out you can I have a thermocouple I can dip it in water at constant temperature okay I know the true temperature of the water I can take the measured temperature find out the difference some of the square of that divided by n will give me variance right so why okay so actually maybe I should just write here no no see this is the why I have written it like this is because this is what we have got through linearization of a nonlinear differential equation right now we are not talking about noise now we will add a noise model to this okay so I am I am composing a model okay through this Taylor series linearization plus I am attaching to it noise models okay so now if I do a discretization of that model under these assumptions okay then you know I get this model okay now there is a little bit of algebra in between what I have done here is this term here okay I will get this term okay I will just do it here see I have this model dx by gt is equal to ax plus bu plus hd when I discretize this and then we are assuming that ut is equal to uk and dt is equal to dk this is for sampling interval tk my capital T is the sampling time okay during this interval we are assuming that the manipulate variables are piecewise constant and the disturbances are piecewise constant okay if I do a discretization of this system okay I will get xk plus 1 is equal to pi xk plus gamma uk plus psi dk okay I will get this psi dk now this psi dk I want to call this as wk okay I want to call this psi dk as wk and then see we have assumed that we have assume that expected value of dk is equal to 0 and covariance of dk is equal to qd this is what we have assume right this is what we have assume now if I define this new variable wk which is psi times dk okay what is expected value of wk is equal to psi expected value of dk which is equal to 0 because expected value of dk is 0 so expected value of psi times dk is also 0 okay and then you can show with a little bit of algebra that covariance of wk which is expected value of psi dk psi dk transpose okay this quantity here will turn out to be psi qd psi transpose this quantity here ends up to be psi qd psi transpose okay so this is what I have done here just look at this okay I am defining this wk to be psi dk my expected value of wk will be psi times expected value of dk since expected value of dk is 0 I get 0 here covariance of wk will be expected value of wk wk transpose that will just turn out to be is this okay everyone with me on this so I am calling this quantity I am calling this quantity psi qd psi transpose as q okay this is because yeah no it is not colored will happen that is a good question it is correlated within itself but it is not correlated in time you say it is colored only when it is time correlated okay it will be correlated in space okay so elements of w1 w2 will be correlated but yeah so time correlation is different from spatial correlation okay so I want to work with this simplified model okay I have done all this algebra to show the connection with the physical model which you get from linearization okay so this is the model which I want to work with xk plus 1 is equal to phi xk plus gamma uk what is wk here wk quantifies those inputs which are affecting the dynamics and which we are not majoring okay it is an effect of those inputs see what are these dk dk are unmeasured disturbances okay so this quantity we also call this as a state uncertainty okay this is state noise or state uncertainty in the state dynamics because there are some other inputs other than u which are influencing the dynamics those are quantified by w okay and what is b is the measurement noise or measurement uncertainty okay I have a model for this I have a model for this what is the model 0 mean white noise you know what is the white noise right there is no time correlation okay so 0 mean white noise signal except earlier we looked at white noise which was a scalar now we are talking of a white noise vector okay concept does not change there is no time correlation there is no time correlation that is what is important okay so wk wk minus 1 wk minus 2 are uncorrelated expected value of wk wk minus j transpose is always 0 that is what is meaning of white noise okay so this w this w is not correlated in time okay the same is true about vk vk is a random error in the measurement which is not correlated in time what is the meaning of being white noise there is no time correlation okay elements of w w1 w2 w3 they can be correlated with each other but there is no time correlation okay that is critical okay now I have this model that means I know ? gamma c matrices I have models for w and v how do I optimally estimate the states okay what is the primary requirement how is the design error between estimate under truth should be as small as possible how do you define as small as possible cross correlation some of the squares yes some of the squares some of the squares of error should be close to 0 or the some of the square of error should be as small as possible but some of the squares you have to be little bit careful these are vectors so error transpose error so to norm so you can say norm of error vector you know maybe one norm to norm some norm of the error vector should be as small as possible okay so let us see how to how Kalman solved this problem now stop me wherever you want if you feel sleepy just tell me because I have to change gear and we do get into little bit difficult stuff so we have a stochastic state space model okay we have a stochastic state space model why it is a stochastic state space model there are deterministic inputs there are stochastic inputs what is a deterministic input you stochastic input is w okay so actually x by virtue of the fact that w is a stochastic process x also becomes a stochastic process okay x also becomes a stochastic process and w is a very nice stochastic process it is white noise 0 mean x is not simply you know it does not have such a simple behavior it has more complex behavior because this w is going through this dynamics okay so in some way w is white noise x will not be a white noise because current x depends upon past x okay so x is not going to be a white noise w is a white noise v is a white noise and we are dealing with a stochastic system now stochastic difference equation the measurements to increase your trouble the measurements are also you know corrupted with noise so life is not easy because there are two sources of uncertainty one in the state dynamics other in the measurements okay and you want to systematically handle this let us make an assumption that measurement noise and the state noise are uncorrelated okay let us make a simplifying assumption okay we make simplifying assumptions so that we get a nice problem which can be solved easily through the maths that we know and then you get some insights and then you build upon it and then try to solve the complex problem that is a trick which is normally done so well what if wk and vk are correlated can you solve the problem you can solve the problem okay but wait we will do that later you may have that so if I am compromising on something I might be able to handle it through adjustment of covariance of w uncertainty so this is a model you have to understand that a model is not really the moment actually you write a model and say that the true system behaves like this model you are itself you are compromised okay the truth is not the model okay yeah but you can never you can never ever develop a model which is exactly equal to the truth that is not possible any you know you can develop a more complex model but that does not mean that it is closer to the I mean you are reach the truth okay only place where the true model or true simulation can be done is inside the computer the real world system when you approximate there are you know there are some this is a reasonable assumption that errors in the measuring device have nothing to do with the disturbances that are affecting the plant this is the perfectly you know logical my fluctuations which are in some flow which are coming because of something happening upstream or some temperature fluctuations because I am getting a temperature from you know some storage tank on the on my building has nothing to do with the measuring error measurement error so measurement error and errors in the disturbances are uncorrelated very logical assumption there is nothing wrong the earlier one is a simplification the simplification okay so this model is now we are at this point we have this model we know the variances of W we know variance of Q okay and now I want to find out I want to get an optimal estimate of X using this model using this dynamic equation together with this stochastic model yeah how will I get Q and D well I we have recently my student did a PhD on how to get Q and R we have published it and I can send you the paper so it is not so easy to answer some of these questions so many times what people do is use R you can find out R is not a difficult Q many time people use it as a tuning parameter you know that there is a 5% uncertainty and you know that is one approach the other approach is you can actually develop identification algorithm to estimate parameters of Q which is what we have recently worked on but so see the it is like a huge puzzle and then you know I have to explain some parts in isolation there is no way of explaining the whole thing together okay so toward the end of the course probably the entire picture will become complete okay so right now assume that somehow you know Q and R okay how you know Q and R do not ask that question right now okay so now there are some preliminaries okay notation is going to be complex okay so just I am making you aware now this set I am calling this set YK Y superscript K it is not Y raise to K it is only a notation it is not Y raise to K what is the meaning of this Y superscript K it is set of all data collected up to point time point K okay so this data consist of U and Y measurements and inputs which are gone to the system from time 0 to time K okay so that set is called as okay what you can show what you can show is that the best estimate the optimal estimate okay of the state is equal to the conditional mean of X conditional X is a random variable because W and V are random variables so X is a random variable see let us go back here W is a random variable V is a random variable now I am going to use the measurements I am going to use the measurements to correct the state estimates observer right so my estimated state is going to be function of Y see the true state is not function of Y estimated state is function of Y because in the observer we use the feedback right Y minus Y hat okay so my estimated state is going to be function of the measurements okay so since W and V themselves are random variables X is actually a stochastic process you agree with me X is a stochastic process okay and you know it will have a mean stochastic process it will have a mean value okay it will also have it will also have variance okay the variance could be time varying see here at any time point the variance is Q for this for any time point variance is R okay X is a stochastic process okay it will have its own probability density function okay it will have its own probability density function okay so what I am saying is that the estimate of X estimate of X best estimate of X is equal to now this proof you can refer to the book by Soderstromm okay I do not have time to do the proof I have given the reference at the end and you can see why this why this conditional mean of X so have you heard of conditional density functions that is have you heard of Bayes rule you must have done Bayes rule sometime okay so probability of event A given that B has occurred okay so you know I can talk of conditional density of a variable X given that Y has occurred okay so same thing I am going to talk here I am going to talk about conditional density of X probability density of X okay given that I have this measurements collected up to time K because to generate an estimate I am going to use all these measurements I am going to use all these measurements to generate an estimate of X okay so let us leave this thing here let us proceed and we can come back to this particular statement this is little okay so now let me do let me start doing predictions okay so what is the conditional expectation of X given measurements up to YK-1 okay I am going to do conditional expectation of X I do not have exact density function right now but I am going to use the equation okay all that I am doing here is I am writing do you see what I am doing here I am saying that XK conditioned on measurements up to K-1 is equal to expected value of this right hand side what is the right hand side Phi XK-1 gamma UK-1 WUK using information up to K-1 okay now I am going to take expectation operator here inside okay so I get Phi expectation of XK-1 given YK-1 okay so we will come up with the notation now this way okay so if you use this definition here use the definition here what is this quantity expected expectation of XK-1 given K-1 see this is XHAT of K-1 given K-1 right okay see I am going to compute this using some tricks okay so till the trick is over just wait and see how you do the algebra okay so now what is expected value of UK-1 UK the deterministic value okay so this will come out of the expectation what is expected value of WK it is a 0 in variable okay so expected value of this is 0 okay so from this equation what I get is this do you see what equation I got the same equation which we have written earlier okay except now interpretations are different when I talked about doing the observable I never said anything about conditional mean or anything of that sort right so that part was never I have now reinterpreting it through a different viewpoint okay so now so what is this quantity conditional mean of X at time instant K using information up to K-1 okay so do not be scared that you have to actually construct and visualize those densities right now we have got a shortcut to find out the new conditional mean if you know the old conditional mean right now how do you know the old conditional mean is will answer that question later but this tells you that the new mean the new conditional mean is 5 times the old conditional mean okay plus this quantity gamma UK okay because expected value of VK is 0 okay what is covariance is the definition of covariance correct just I want to find out conditional covariance I want to find out conditional covariance okay can you find out what is conditional can you work this out that will be easier how do you find out the covariance you compute this quantity XK-X bar K X bar K is the conditional mean see we have computed this will be X bar quantity right mean of XK so mean of XK conditioned on YK-1 which one alright yeah thanks okay so mean propagation we actually found by this equation how mean propagates in time we found by this equation this is how the mean propagates for the stochastic process X the mean propagates according to this equation okay now I am going to subtract this equation okay from the dynamics of XK okay and then so I am going to subtract this mean equation from this equation yeah and then I am going to take the covariance okay so if I subtract this do I get this just check you subtract this equation this is the mean equation this is how the mean propagates I subtract this equation from this equation what will I get see this UK and UK will disappear okay you will get 5 times XK-1- this quantity okay and so I am defining an error here there are two different errors K given K-1 and K-1 given K-1 is everyone with me on this equation is this okay what is the covariance of epsilon K-1 can you compute what is the mean value and what is the covariance for the time being let me tell you that it is mean value with 0 I will prove it I will prove that mean value of this will be 0 but let us say the mean value is 0 how will you find out the covariance so just do it just do it see this WK and epsilon are not correlated WK-1 and epsilon K-1 they are not correlated so I have two errors here prediction error and I have prediction error and estimation error okay I am defining two quantities prediction error and estimation error estimation error is difference between the true X okay and the current estimate at K-1 this is true X and predicted estimate at K okay is this fine so I have this difference equation which governs the error which governs the estimation error okay so my update step is going to be like this okay now I will talk about its covariance a little later are you fine with this definitions I am just doing some preliminaries you know finally I have to derive this Kalman's algorithm for doing optimal estimation okay so my update step is going to be like this okay my update step is going to be like this right now I am using an arbitrary gain LK I do not know how to choose gain LK I want to choose the gain LK okay this is this step is you are familiar with this step you have done this earlier that is new updated estimate is equal to prediction estimate plus a correction, correction coming from the measurements so this is Y which is measured minus Y which is predicted Y okay this difference is used to correct the current state estimate this is the standard thing okay now where I have chosen a gain which is an arbitrary gain matrix okay so here EK is called innovation and then I have just shown what is the relationship of innovation with the estimation error so this particular step is very easy to derive it is not you just look at the three equations and you know I have just substituting for Y hat K given K-1 C X hat K given K-1 and YK is C XK plus VK so you take C common here you will get XK minus right the simple algebra okay so you can just do a little bit of some more ground work and show that the prediction error so the estimation error and the prediction error are related through this equation this again needs a little bit of working and you can very easily prove this equality so epsilon of R here no this I am trying to find out between K given K and K given K-1 I want to find in this relationship okay see what I am doing is I am just combining I am just using this equation I am using this equation and combining it through this I am combining it with you can try and derive this just see okay so right now I am at a point where I have this L matrix okay and I do not know how to choose L matrix I have not chosen it yet okay and I want to come up with a systematic way of choosing L matrix okay I have done some algebra kept some equations ready and then okay let us skip this for the time being let me tell you what is how where I want to reach and then we will do the just a minute where I want to reach finally after doing a lot of algebra in between which will take some time to digest please bring those notes otherwise it is difficult to follow unless you have those notes and if possible you can try to read and come and then see I want to find out the gain matrix such that estimation error variance is minimum okay so this PKK is the covariance of the state at time instant K okay I am going to find out covariance matrix of this error estimation error I want to minimize I want to minimize a trace of this covariance matrix that is what I want to do okay with respect to L I want to choose L in such a way that trace of the covariance matrix covariance matrix of what this P is the covariance matrix of estimation error epsilon KK okay so this is okay X hat KK X hat KK is the estimated value of X at instant K using measurements up to time K XK is the true value okay I can find the covariance of this what is the meaning of covariance what does covariance signify if the variance if you take a simple measurement if variance is large is it a good measurement no so if I want if I want a sensor see what are you doing here you are developing a software sensor soft sensor right you are developing an estimator of unmeasured quantities using measured quantities through a model okay what do you want to say about the possible error in the estimate so it will be smaller large it should be as small as possible okay which statistical quantity quantifies you know spread of the error variance okay so I want to device an observer which is a minimum variance observer okay I want to device an observer which is a minimum variance observer of the estimator which gives you smallest possible variance of the now what is design variable to me is L okay but L is a matrix okay and then we will have to learn a little bit about rules of differentiating a scalar function with respect to a matrix okay so that is why I said bring those notes okay so and then what is the relationship of this pk with all this ? ? qr you know I am going to derive a relationship which will look something like this I am going to develop a recurrence relationship I am going to develop a recurrence relationship which looks like this that updated covariance is old covariance into ? matrix plus q matrix and all that okay and then predicted covariance is equal to something something okay so I am going to develop all these through a lot of algebra I am going to develop a relationship bit for pkk okay I am going to develop this relationship between pkk and pk-1 and then I want to minimize those functions okay with respect to a matrix so we have to do a lot of algebra to understand how to differentiate a scalar function with respect to matrix and then so this particular problem actually was solved by Kalman in 1964 and it led to an explosion of algorithms which are used for soft sensing these methods what I am talking about is not just used in control it is used in speech recognition this algorithms are very very generic Kalman filtering state estimation algorithms are used in target tracking used in interpreting data from radar you know you want to find out see you are getting some measurements you know from this radar which is moving you want to find out the coordinates of the aeroplane where exactly it is it could be relevant while it is landing or while it is travelling or you have a enemy aircraft and then you want to know where it is and you want to shoot whatever okay so you should know the probability of you know if you are hitting you should know how close you know what is the error in the estimate you want an estimate to be as close as possible to the truth okay so variance should be small the way of mathematically saying this is the variance should be small of the estimated value and just remember when you have measurements and you are reconstructing the position through a model you only have an estimate so the estimate is also a random variable and you better know about its behavior okay so that is why all this trouble so this problem which was solved by him has led to a huge development a rare occasion where engineer contributed to mathematics and which has led to a huge developments in engineering field you know we lot of things that we do in image reconstruction or all kinds of things uses this these ideas okay before I close let me take a minute to talk about we are finally uploading the tutorial problems today we have divided into two problems there are two reactor problems there are 12 students from chemical engineering background so we will give them those two reactor problems they are CSTR with exothermic reaction and so they will do those problems there are three problems which are non or which can be appreciated by anyone okay that is what we think one problem of that is a fermenter problem okay so fermentation is the azure process where you take glucose put yeast and create alcohol it is familiar to you from or to the human race for last I do not know how many thousand years so you are giving just a mathematical model to do it in a vessel okay so there is a substrate which is coming in okay then there is a biomass which reacts and converts it into the product which is alcohol okay so the simple model for that second model is one stirred tank heater system which we have in the lab I will take you there to show it so that is simple two tanks in series there are two heaters in these two tanks and I am giving you a model for that it is very easy to understand for anyone with any background does not require any there is nothing special chemical engineering about it third system is human body problem is to major glucose for a diabetic patient and the manipulate variables is food okay and insulin okay so instead of food you can think of a person is hospitalized and you know you have two syringes one is glucose and other is insulin syringe and then you have to do dosing to control the glucose level in the blood okay so this third problem is also control problem and anyone can appreciate this okay I have uploaded my programs in the model if I do not know whether you have seen them but you can use my programs the weightage for this in the boat is 25 marks and I expect that you the groups do not copy okay so if I find any copying I am going to check line by line if I find copying there is only one grade that is 0 out of 25 okay so no copying whatever you can do by talking to each other so this is the program which I have uploaded I have shown here how to do simulation for the full tank system all of you know the full tank system very well okay so you know how to linearize this get a linear state model a continuous time in discrete time how to do open loop simulation how to inject PRBS perturbations and you know finally find out the Jacobian matrix and how to it how to do noise simulation everything is shown here so this is a demo program you can you are allowed to start from this program you can start modifying this program okay the first deadline is 26th so first thing that you have to do is whatever we have learned in the course where to do on the system okay so first thing is system identification and linearization okay so linearize the system get transfer function models in continuous time discrete time and also inject perturbations use ident toolbox identification toolbox and get you know box Jenkins ARX RMAX all kinds of models and compare them.