Modeling, Simulation and System Identification Using MATLAB®
Mohsen Mirtalebi
Dr. Jose Ramos Aaron Ferrell
Mark Debruler I.
Abstract:
Modeling in engineering is faced to the real world data analysis to achieve the best mathematical model. The model that best fit into the given data is usually named y_fitted. We used the same notation to identify the attempted model. This report illustrates how we processed the given data to obtain the best y_fitted.
II.
Introduction:
Our experiment has two parts. Part one of this report shows our attempt to find a model for the given data in the file named Lab5_1.mat. There were three given model to try out if it can fit into the given data. The following models were given: 2
1)
y = a2 x + a1 x + a0 .
2)
y = a.e .
3)
y = x / (a + b.x).
bx
The second part was to identify the model was best fitted for the given data in the file named Lab5_2.mat. This information was processed and the model was identified. The part two of this lab most likely a type of system identification problem.
III.
Equipment:
The only equipment we used was the laboratory’s computer including MatLab® version 6 release 12.
IV.
Results:
The following information illustrates our attempts to find the appropriate model for the given data in part one of the experiments. A.
2
First attempt to find out that f(x) = a 2 x + a1 x + a0 can be fitted as a desired model: a. MatLab® source file:
X=[x.^2 x ones(length(x),1) ones(length(x),1)]; ]; Y=y; A=inv(X'*X)*X'*Y; Y_fitted=X*A; e=Y-Y_fitted; plot(x,Y_fitted,'b',x,y,'r.') title('First Model'); xlabel('X'); ylabel('Y_fitted'); pause plot(x,e,'r.') title('Error'); xlabel('x'); ylabel('Y-Y_fitted'); pause option=[1 0]; pt1='Histogram'; pt2=' '; [xdata,ydata,xgauss,ygauss]=normal(e,option,pt1,pt2);
b. Plots for the first attempt:
This figure shows the found model vs. the given data distribution. Note that the given data is shown dotted.
Error diagram emphasizes on inappropriate found model
The histogram shows that the found model is not distributed normal. B.
Second attempt to find out that the given model can be fitted as a desired model: a. MatLab® source file:
x_i=[x ones(length(x),1)]; y_i=y; P=regress(y_i,x_i); a=P(2); b=P(1); log_y=log(a)*log(b*x_i); y_fitted=log(log_y); plot(x,y,'.',x_i,y_fitted,'r.'); title('Second Model'); xlabel('X'); ylabel('Y_fitted'); pause; y_1=[y zeros(length(y),1)]; e_i=y_1-y_fitted; plot(x_i,e_i); title('Error'); xlabel('x'); ylabel('Y-Y_fitted'); pause option=[1 0]; pt1='Histogram'; pt2=' '; [xdata,ydata,xgauss,ygauss]=normal(e,option,pt1,pt2); b. Plots for the second attempt: attempt:
This figure shows the found model vs. the given data distribution. Note that the given data is shown dotted.
Error diagram emphasizes on inappropriate found model
The histogram shows that the found model is not distributed normal.
C.
Third attempt to find out that the given model can be fitted as a desired model: a. MatLab® source file:
x_i=[1./x ones(length(x),1)];
y_i=y; y1=1./y_i; P=inv(x_i'*x_i)*x_i'*y1; a=P(1); b=P(2); e_transf=y1-x_i*P; y_fitted=x./(a+b*x); plot(x,y,'.',x,y_fitted,'r.'); pause; e=y-y_fitted; plot(x,e,'r.'); pause plot(x,e_transf,'r.') pause option=[1 0]; pt1='Part 2'; pt2=' '; [xdata,ydata,xgauss,ygauss]=normal(e,option,pt1,pt2);
b. Plots for the third attempt:
This figure shows the found model vs. the given data distribution. Note that the given data is shown dotted and almost matched with the found model.
The error is distributed in a straight line that is the sign of minimum error compared to the other models.
The histogram shows that the found model is distributed normal and can be used as an appropriate model.
The Following information is the result of process to identify the model for the given data in the file Lab5_2.mat. A.
MatLab® source file: load lab5_2; x=y; X=[x(3:N) x(2:N-1) x(1:N-2)]; x (1:N-2)]; U=[u(1:N-2)]; A=inv(X'*X)*X'*U P=[1/T^2 0 0; -2/T^2 1/T 0; 1/T^2 -1/T 1]; R=inv(P)*A alpha1=A(2)/A(1); alpha2=A(3)/A(1); beta0=1000/A(1); h(1)=beta0; h(2)=-alpha1*beta0; h(3)=-alpha1*h(2)-alpha2*h(1); for k=3:N h(k)=-alpha1*h(k-1)-alpha2*h(k-2); end plot(h); title('Transfer Function Through Difference Eqs.'); xlabel('k'); ylabel('h(k)'); pause; y_fitted=conv(h,u); plot(t,y_fitted(1:N),'.'); title('Y_fitted through impulse response of h(k)'); xlabel('k'); ylabel('Y_fitted(k)');
B.
Plots for the second part:
The graph shows the transfer function of the given data
This graph shows the discrete form of impulse response of the identified system.
V.
Discussion:
The first part of the experiment was about finding the best model fitted into the given data. After processing the data and finding constant coefficients we tried three models. For the first and the second model we could not get a constant error graph as well as a symmetric histogram these two graph beside the graph of the attempted model vs. the real world data graph guided us to easily reject the first two models. Similarly through the same process we could successfully verify and confirm the third model because of an almost flat error graph and a symmetric histogram. The second part was performed through extracting constant coefficients from the given data and plugs it in the difference equation to find the system transfer function.
VI.
Conclusion:
We think that the whole experiment was full of valuable information to be set as a model line in the future to deal with the real world data.