TheCost = MIMO_ML_Cost(data, Theta, x, ModelVar); Calculates the cost function for identifying plant models with arb. signals Output arguments TheCost = value cost function Input arguments data = structure containing the non-parametric data required for the identification data.Y = output DFT spectra of 1 or nu independent MIMO experiments 1 MIMO experiment: ny x F nu MIMO experiments: ny x nu x F data.U = input DFT spectra of 1 or nu independent MIMO experiments 1 MIMO experiment: nu x F nu MIMO experiments: nu x nu x F data.freq = vector of frequency values (Hz), size: F x 1 data.Ts = sampling time (s) data.CY = (sample) noise covariance matrix of Y 1 MIMO experiment: ny x ny x F nu MIMO experiments: ny x ny x nu x F data.CU = (sample) noise covariance matrix of U 1 MIMO experiment: nu x nu x F nu MIMO experiments: nu x nu x nu x F data.CYU = (sample) noise covariance matrix of U 1 MIMO experiment: ny x nu x F nu MIMO experiments: ny x nu x nu x F data.sqrtCYinv = CY^(-0.5); if OE 1 MIMO experiment: ny x ny x F nu MIMO experiments: ny x ny x nu x F data.DC = 1 if DC present otherwise 0 data.Nyquist = 1 if Nyquist frequency present otherwise 0 data.NumberExp = number of independent MIMO experiments (1 or nu) Theta = estimated value plant, noise, and initial conditions parameters structure with fields 'A', 'B', 'Ig' Theta = struct('A',[],'B',[], 'Ig', []) Theta.A = 1 x (OrderA+1) Theta.A(r) = coefficient a(r-1) of Omega^(r-1) Theta.B = ny x nu x (OrderB+1) Theta.B(i,j,r) = coefficient b(i,j,r-1) of Omega^(r-1) Theta.Ig = ny x (OrderIg+1) Theta.Ig(i,r) = coefficient ig(i,r-1) of Omega^(r-1) x = structure containing (jwk) or (zk^-1) values x.Plant = plant model, dimension: F x 1 ModelVar = contains the information about the model to be identified structure with fields 'Transient', 'ThePlane', 'TheModel', 'Reciprocal', ... ModelVar.Transient = 1 then the initial conditions of the plant and/or noise are estimated ModelVar.PlantPlane = plane of the plant model 's': continuous-time; 'w': sqrt(s)-domain 'z': discrete-time; '': plane not defined ModelVar.Struct = model structure 'EIV': errors-in-variables (noisy input-output data) 'OE': generalised output error (known input, noisy output) ModelVar.nu = number of inputs ModelVar.ny = number of outputs Copyright (c) Rik Pintelon, Vrije Universiteit Brussel - dept. ELEC, November 2009 All rights reserved. Software can be used freely for non-commercial applications only.
0001 function TheCost = MIMO_ML_Cost(data, Theta, x, ModelVar); 0002 % 0003 % TheCost = MIMO_ML_Cost(data, Theta, x, ModelVar); 0004 % 0005 % Calculates the cost function for identifying plant models with arb. signals 0006 % 0007 % 0008 % Output arguments 0009 % 0010 % TheCost = value cost function 0011 % 0012 % 0013 % Input arguments 0014 % 0015 % data = structure containing the non-parametric data required for the identification 0016 % data.Y = output DFT spectra of 1 or nu independent MIMO experiments 0017 % 1 MIMO experiment: ny x F 0018 % nu MIMO experiments: ny x nu x F 0019 % data.U = input DFT spectra of 1 or nu independent MIMO experiments 0020 % 1 MIMO experiment: nu x F 0021 % nu MIMO experiments: nu x nu x F 0022 % data.freq = vector of frequency values (Hz), size: F x 1 0023 % data.Ts = sampling time (s) 0024 % data.CY = (sample) noise covariance matrix of Y 0025 % 1 MIMO experiment: ny x ny x F 0026 % nu MIMO experiments: ny x ny x nu x F 0027 % data.CU = (sample) noise covariance matrix of U 0028 % 1 MIMO experiment: nu x nu x F 0029 % nu MIMO experiments: nu x nu x nu x F 0030 % data.CYU = (sample) noise covariance matrix of U 0031 % 1 MIMO experiment: ny x nu x F 0032 % nu MIMO experiments: ny x nu x nu x F 0033 % data.sqrtCYinv = CY^(-0.5); if OE 0034 % 1 MIMO experiment: ny x ny x F 0035 % nu MIMO experiments: ny x ny x nu x F 0036 % data.DC = 1 if DC present otherwise 0 0037 % data.Nyquist = 1 if Nyquist frequency present otherwise 0 0038 % data.NumberExp = number of independent MIMO experiments (1 or nu) 0039 % 0040 % Theta = estimated value plant, noise, and initial conditions parameters 0041 % structure with fields 'A', 'B', 'Ig' 0042 % Theta = struct('A',[],'B',[], 'Ig', []) 0043 % Theta.A = 1 x (OrderA+1) 0044 % Theta.A(r) = coefficient a(r-1) of Omega^(r-1) 0045 % Theta.B = ny x nu x (OrderB+1) 0046 % Theta.B(i,j,r) = coefficient b(i,j,r-1) of Omega^(r-1) 0047 % Theta.Ig = ny x (OrderIg+1) 0048 % Theta.Ig(i,r) = coefficient ig(i,r-1) of Omega^(r-1) 0049 % 0050 % x = structure containing (jwk) or (zk^-1) values 0051 % x.Plant = plant model, dimension: F x 1 0052 % 0053 % ModelVar = contains the information about the model to be identified 0054 % structure with fields 'Transient', 'ThePlane', 'TheModel', 'Reciprocal', ... 0055 % ModelVar.Transient = 1 then the initial conditions of the plant and/or noise are estimated 0056 % ModelVar.PlantPlane = plane of the plant model 0057 % 's': continuous-time; 0058 % 'w': sqrt(s)-domain 0059 % 'z': discrete-time; 0060 % '': plane not defined 0061 % ModelVar.Struct = model structure 0062 % 'EIV': errors-in-variables (noisy input-output data) 0063 % 'OE': generalised output error (known input, noisy output) 0064 % ModelVar.nu = number of inputs 0065 % ModelVar.ny = number of outputs 0066 % 0067 % 0068 % Copyright (c) Rik Pintelon, Vrije Universiteit Brussel - dept. ELEC, November 2009 0069 % All rights reserved. 0070 % Software can be used freely for non-commercial applications only. 0071 % 0072 0073 % initialisation variables 0074 NumberExp = data.NumberExp; 0075 ny = ModelVar.ny; 0076 nu = ModelVar.nu; 0077 F = length(data.freq); 0078 TheError = zeros(NumberExp*ny, F); 0079 dataee = data; % information about 1 MIMO experiment (see below) 0080 dataee.Y = zeros(ny, F); % output of 1 MIMO experiment 0081 dataee.U = zeros(nu, F); % input of 1 MIMO experiment 0082 dataee.CY = zeros(ny, ny, F); % output covariance of 1 MIMO experiment 0083 switch ModelVar.Struct 0084 case 'EIV' 0085 dataee.CU = zeros(nu, nu, F); % input covariance of 1 MIMO experiment 0086 dataee.CYU = zeros(ny, nu, F); % output-input covariance of 1 MIMO experiment 0087 case 'OE' 0088 dataee.sqrtCYinv = zeros(ny, ny, F); 0089 end % switch 0090 0091 % transfer functions and polynomials 0092 PolyTrans = MIMO_ML_CalcPolyTrans(Theta, x); 0093 0094 for ee = 1:NumberExp 0095 0096 % data of MIMO experiment no. ee 0097 if NumberExp > 1 0098 dataee.Y(:,:) = data.Y(:,ee,:); 0099 dataee.U(:,:) = data.U(:,ee,:); 0100 dataee.CY(:,:,:) = data.CY(:,:,ee,:); 0101 switch ModelVar.Struct 0102 case 'EIV' 0103 dataee.CU(:,:,:) = data.CU(:,:,ee,:); 0104 dataee.CYU(:,:,:) = data.CYU(:,:,ee,:); 0105 case 'OE' 0106 dataee.sqrtCYinv(:,:,:) = data.sqrtCYinv(:,:,ee,:); 0107 end % switch 0108 else % 1 MIMO experiment 0109 dataee.Y(:,:) = data.Y; 0110 dataee.U(:,:) = data.U; 0111 dataee.CY(:,:,:) = data.CY; 0112 switch ModelVar.Struct 0113 case 'EIV' 0114 dataee.CU(:,:,:) = data.CU; 0115 dataee.CYU(:,:,:) = data.CYU; 0116 case 'OE' 0117 dataee.sqrtCYinv(:,:,:) = data.sqrtCYinv; 0118 end % switch 0119 end % if more than 1 MIMO experiment 0120 0121 % calculate a hermitian square root of the inverse 0122 % of the covariance of the output error (NY-G*NU) 0123 switch ModelVar.Struct 0124 case 'EIV' 0125 PolyTrans = MIMO_ML_InvCovOutputError(dataee, PolyTrans); 0126 case 'OE' 0127 PolyTrans.sqrtCEinv = dataee.sqrtCYinv; 0128 end % switch 0129 0130 % prediction Error; size ny x F 0131 Error = MIMO_ML_PredError(dataee, PolyTrans); 0132 0133 % put experiment no. ee in the prediction error vector 0134 SelectRows = [(ee-1)*ny+1:ee*ny]; 0135 TheError(SelectRows, :) = Error; 0136 0137 end % ee, number of MIMO experiments 0138 0139 % cost function 0140 TheCost = norm(TheError(:))^2;