You are on page 1of 10

2011

DiSiProL record

Y.Yella Reddy IIT BHUBANESWAR 9/20/2011

DiSiProL record System Identification Aim :To do direct modeling of a Plant using Genetic algorithm. Simulation Tool : MATLAB version 2010a. Theory :

2011

System Identification is the concept where we make a replica of a Plant (mechanical, etc.) in Electrical domain. A Plant have 3 major components Input X(s) Plant Transfer function H(s) Input H(s) Output Output Y(s) Where they are related by Y(s) = H(s) * X(s) in frequency domain And y(t) = conv(h(t),x(t)) in time domain. A system can be modeled in 2 methods. They are Direct modeling. Indirect modeling. Here our aim is to Direct modeling of the plant. In this method, we convolve input of plant X with plant transfer function H to get output Y and noise is added to the Y to get derived output D. In parallel we develop a model of this by initializing Transfer function (h) coefficients as zeros and the input X is convolved with h to get model output y. y is subtracted from D to get error which is used to update Transfer function Coefficients of Model in every iteration using Adaptive Least mean Square(LMS) Algorithm. Here I show the Block diagram

IIT BHUBANESWAR

DiSiProL record

2011

MATLAB function for System Identification.


clc; close all; clear all; N=input('No of input samples :'); %input number of samples.

Learning_Para=input('Enter the Learning Parameter value:'); % Learning rate of the model %Signal Power to noise power snr=input('Enter the snr value : '); m=[];

%------------------------------ Intialization -----------------------------% x=randint(1,30,[0 1023]); x1=zeros(1,30); %------------------------- Generating binary code ------------------------% for i=1:1:30 x1(i)=x(i); for j=1:1:10 X(i,11-j)=rem(x1(i),2); x1(i)=floor(x1(i)/2); end end W = X'; for l=1:1:20 W1 = zeros (10,1); W2 = zeros (10,1); W3 = zeros (10,1); for i=1:1:10 for j=1:1:10 W1(i)= W1(i)+ power(2,-j)*W(i,j); W2(i)= W2(i)+ power(2,-j)*W(i,j+10); W3(i)= W3(i)+ power(2,-j)*W(i,j+20)'; end end

IIT BHUBANESWAR

DiSiProL record
W_new=[W1 W2 W3];

2011

for i = 1:1:10 Input_Plant= rand(1,N); % input to the plant with mean zero and input to model is also same. % Model Parameters Input_Model=Input_Plant; sp=var(Input_Plant); np =(sp)*power(10,-(snr/10)); %System Weights Wp = [0.26 0.93 0.26]; %Noise to be added Noise=sqrt(np)*(rand(1,N)-0.5); % Plant Output. Plant_Output(1)=Input_Plant(1)*Wp(1); Plant_Output(2)=Input_Plant(2)*Wp(2)+Input_Plant(1)*Wp(1); %Model Output Model_Output(1)=Input_Model(1)*W_new(i,1); Model_Output(2)=Input_Model(2)*W_new(i,1)+Input_Model(1)*W_new(i,2); % Model output with added noise Model_Output(1)=tan(Model_Output(1))+Noise(1); Model_Output(2)=tan(Model_Output(2))+Noise(2); % Error error(1)=Plant_Output(1)-Model_Output(1); error(2)=Plant_Output(2)-Model_Output(2); for j=3:1:N %Outputs Plant_Output(j)=Input_Plant(j)*Wp(1)+Input_Plant(j1)*Wp(2)+Input_Plant(j-2)*Wp(3); Model_Output(j)=Input_Model(j)*W_new(i,1)+Input_Model(j1)*W_new(i,2)+Input_Model(j-2)*W_new(i,3); %White gaussian noise signal added to the output of the plant. Model_Output(j)=tan(Model_Output(j))+Noise(j); error(j)=Plant_Output(j)-Model_Output(j); end error_square=power(error,2); MSE(i)=sum(error_square)/N; end MSE_arranged=sort(MSE,'ascend'); %-------- sorting in descending order %-------------- Discarding Lower Strata and Starting Crossover------------%

IIT BHUBANESWAR

DiSiProL record
%step1 - swapping X data in the descending order for i=1:1:10 for j=1:1:10 if (MSE(j)==MSE_arranged(i)) Z(i,:)=W(j,:); end end end %step2 - discard lower 2 data values of Y and Z(Probability = 0.8) MSE_arranged=MSE_arranged(1:8)/N; Z=Z(1:8,:); %step3 - starting crossover n=randperm(8); m=ceil(rand(1)*10); for i=1:2:7 CrossoverZ1(n(i),1:10)=[Z(n(i),1:m) Z(n(i+1),m+1:10)]; CrossoverZ1(n(i+1),1:10)=[Z(n(i+1),1:m) Z(n(i),m+1:10)]; CrossoverZ2(n(i),1:10)=[Z(n(i),11:m+10) Z(n(i+1),m+11:20)]; CrossoverZ2(n(i+1),1:10)=[Z(n(i+1),11:m+10) Z(n(i),m+11:20)]; CrossoverZ3(n(i),1:10)=[Z(n(i),21:m+20) Z(n(i+1),m+21:30)]; CrossoverZ3(n(i+1),1:10)=[Z(n(i+1),21:m+20) Z(n(i),m+21:30)]; end Crossover_Child1=CrossoverZ1; Crossover_Child2=CrossoverZ2; Crossover_Child3=CrossoverZ3;

2011

%--------------------------- Starting Mutation ---------------------------% %Probability =0.1, change any single random value in each to opposite(0to1) Mutation_Child1=Crossover_Child1; Mutation_Child2=Crossover_Child2; Mutation_Child3=Crossover_Child3;

for i=1:1:8 o=ceil(rand(1)*10); if (Crossover_Child1(i,o)==0) Mutation_Child1(i,o)=1; else if (Crossover_Child1(i,o)==1)

IIT BHUBANESWAR

DiSiProL record
Mutation_Child1(i,o)=0; end end o1=ceil(rand(1)*10); if (Crossover_Child2(i,o1)==0) Mutation_Child2(i,o1)=1; else if (Crossover_Child2(i,o1)==1) Mutation_Child2(i,o1)=0; end end o2=ceil(rand(1)*10); if (Crossover_Child3(i,o2)==0) Mutation_Child3(i,o2)=1; else if (Crossover_Child3(i,o2)==1) Mutation_Child3(i,o2)=0; end end end %Parent,Crossover and Mutation childs are made Final_data1=[Z(1:8,1:10); Crossover_Child1; Mutation_Child1]; Final_data2=[Z(1:8,11:20); Crossover_Child2; Mutation_Child2]; Final_data3=[Z(1:8,21:30); Crossover_Child3; Mutation_Child3]; Final_data = [Final_data1 Final_data2 Final_data3]; Wn1 = zeros (24,10); Wn2 = zeros (24,10); Wn3 = zeros (24,10); for i=1:1:24 for j=1:1:10 Wn1(i) = Wn1(i) + power(2,-j)*Final_data(i,j); Wn2(i) = Wn2(i) + power(2,-j)*Final_data(i,j+10); Wn3(i) = Wn3(i) + power(2,-j)*Final_data(i,j+20); end end Wn_new=[Wn1 Wn2 Wn3]; for i = 1:1:24 Input_Plant1= rand(1,N); to model is also same. % Model Parameters Input_Model1=Input_Plant1; sp=var(Input_Plant1);

2011

% input to the plant with mean zero and input

IIT BHUBANESWAR

DiSiProL record
np =(sp)*power(10,-(snr/10)); %Noise to be added Noise1=sqrt(np)*(rand(1,N)-0.5); % Plant Output. Plant_Output1(1)=Input_Plant1(1)*Wp(1); Plant_Output1(2)=Input_Plant1(2)*Wp(1)+Input_Plant1(1)*Wp(2);

2011

%Model Output Model_Output1(1)=Input_Model1(1)*Wn_new(i,1); Model_Output1(2)=Input_Model1(2)*Wn_new(i,1)+Input_Model1(1)*Wn_new(i,2); % Plant output with added noise and non linearity Model_Output1(1)=tan(Model_Output1(1))+Noise(1); Model_Output1(2)=tan(Model_Output1(2))+Noise(2); % Error error1(1)=Plant_Output1(1)-Model_Output1(1); error1(2)=Plant_Output1(2)-Model_Output1(2); for j=3:1:N %Outputs Plant_Output1(j)=Input_Plant1(j)*Wp(1)+Input_Plant1(j1)*Wp(2)+Input_Plant1(j-2)*Wp(3); Model_Output1(j)=Input_Model1(j)*Wn_new(i,1)+Input_Model1(j1)*Wn_new(i,2)+Input_Model1(j-2)*Wn_new(i,3); %White gaussian noise signal added to the output of the plant. Model_Output1(j)=tan(Model_Output1(j))+Noise1(j); error1(j)=Plant_Output1(j)-Model_Output1(j); end error_square1=power(error1,2); MSE1(i)=sum(error_square1)/N; end MSE_arranged1=sort(MSE1,'ascend'); %-------- sorting in descending order %-------------- Discarding Lower Strata and Starting Crossover------------% %step1 - swapping X data in the descending order for i=1:1:24 for j=1:1:10 if (MSE1(j)==MSE_arranged1(i)) Z1(i,:)=Final_data(j,:); end end end

IIT BHUBANESWAR

DiSiProL record

2011

MSE_arranged2(l,1:10)=MSE_arranged1(1:10); Z1=Z1(1:10,:); W = Z1; end for k=1:1:20 m(k)=MSE_arranged2(k,1); end

plot(sort(m,'descend'));%'--rs','LineWidth',2,... %'MarkerEdgeColor','k',... %'MarkerFaceColor','g',... %'MarkerSize',10) xlabel('No. of Generations'); ylabel('Minimum value of MSE');

%TESTING W_New = Z1(1,:); W1 = 0; W2 = 0; W3 = 0; for j=1:1:10 W1 = W1+power(2,-j)*W_New(j); W2 = W2+power(2,-j)*W_New(j+10); W3 = W3+power(2,-j)*W_New(j+20); end s=30; Input_test= rand(1,s); Weights_Plant = [0.26 0.91 0.26]; Weights_Model = [W1 W2 W3]; for j= 3:1:s

Plant_Out_test(1)= Input_test(1)*Weights_Plant(1); Plant_Out_test(2)= Input_test(2)*Weights_Plant(1)+Input_test(1)*Weights_Plant(2); Plant_Out_test(j)= Input_test(j)*Weights_Plant(1)+Input_test(j1)*Weights_Plant(2)+Input_test(j-2)*Weights_Plant(3); Out_Model_test(1)= Input_test(1)*Weights_Model(1); Out_Model_test(2)= Input_test(2)*Weights_Model(1)+Input_test(1)*Weights_Model(2);

IIT BHUBANESWAR

DiSiProL record
Out_Model_test(j)= Input_test(j)*Weights_Model(1)+Input_test(j1)*Weights_Model(2)+Input_test(j-2)*Weights_Model(3); error_test(1)= Plant_Out_test(1)-Out_Model_test(1); error_test(2)= Plant_Out_test(2)-Out_Model_test(2); error_test(j)= Plant_Out_test(j)-Out_Model_test(j); end figure, p=1:1:s; plot(p,Plant_Out_test,'-ro',p,Out_Model_test,'-.b'); legend('Plant Out test','Out Model test'); title('Comparision of outputs of Plant and Model during testing'); xlabel('iterations'); ylabel('Output') square_error= error_test.^2; SSE=sum(square_error); SSE; W_new

2011

Results
0.6787 0.6787 0.6787 0.6787 0.6787 0.6787 0.6787 0.6787 0.6787 0.6787 0.2090 0.2090 0.2090 0.2090 0.2090 0.2090 0.2090 0.2090 0.2090 0.2090 0.3115 0.3115 0.3115 0.3115 0.3115 0.3115 0.3115 0.3115 0.3115 0.3115

Number of Samples N=1000; Learning Parameter Mu=0.15 SNR=30db;

IIT BHUBANESWAR

DiSiProL record Plots

2011

Conclusion :
I plotted the following Plots Error Square Plot Log of Normalized Square Error Plot Testing Plot of Outputs of the Plant and Model

IIT BHUBANESWAR

You might also like