function Deriv = MIMO_ML_CalcDeriv(xMat, PolyTrans, ModelVar); Calculates the derivative of the rational transfer function matrix G = B/A, and the rational vector function Tg = Ig/A w.r.t. the model parameters. For the transfer function matrix G the derivative of vec(G) is calculated Output parameter Deriv = structure containing the derivative of vec(G), and Tg, w.r.t. all the plant model parameters a, b, ig Deriv.vecGa = derivative vec(G) w.r.t. a; size ny*nu x (na+1) x F Deriv.vecGb = derivative vec(G) w.r.t. b; size ny*nu x ny*nu*(nb+1) x F b = reshape(permute(Theta.B, [3,1,2]), [ny*nu*(nb+1),1]) Deriv.Tga = derivative Tg w.r.t. a; size ny x (na+1) x F Deriv.Tgig = derivative Tg w.r.t. ig; size ny x ny*(nig+1) x F ig = reshape(permute(Theta.Ig, [2,1]), [ny*(nig+1),1]) Input parameters xMat = structure with tables of powers of (jwk)^r or (zk^-r) xMat.Plant = plant model, size: F x max order PolyTrans = structure containing the polynomials and transfer functions evaluated in x PolyTrans.A = denominator polynomial plant transfer function evaluated in x.Plant, size 1 x F PolyTrans.G = plant transfer matrix evaluated in x.Plant, size ny x nu x F PolyTrans.Tg = plant transient term evaluated in x.Plant, size ny x F 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.RecipPlant = 1 if plant model is reciprocal: G(i,j) = G(j,i) ModelVar.nu = number of inputs ModelVar.ny = number of outputs ModelVar.na = order polynomial A ModelVar.nb = order matrix polynomial B ModelVar.nig = order vector polynomial Ig Copyright (c) Rik Pintelon, Vrije Universiteit Brussel - dept. ELEC, 27 November 2009 All rights reserved. Software can be used freely for non-commercial applications only.
0001 function Deriv = MIMO_ML_CalcDeriv(xMat, PolyTrans, ModelVar); 0002 % 0003 % function Deriv = MIMO_ML_CalcDeriv(xMat, PolyTrans, ModelVar); 0004 % 0005 % Calculates the derivative of the rational transfer function matrix G = B/A, 0006 % and the rational vector function Tg = Ig/A w.r.t. the model parameters. For the transfer 0007 % function matrix G the derivative of vec(G) is calculated 0008 % 0009 % Output parameter 0010 % 0011 % Deriv = structure containing the derivative of vec(G), and Tg, w.r.t. all the plant model parameters a, b, ig 0012 % Deriv.vecGa = derivative vec(G) w.r.t. a; size ny*nu x (na+1) x F 0013 % Deriv.vecGb = derivative vec(G) w.r.t. b; size ny*nu x ny*nu*(nb+1) x F 0014 % b = reshape(permute(Theta.B, [3,1,2]), [ny*nu*(nb+1),1]) 0015 % Deriv.Tga = derivative Tg w.r.t. a; size ny x (na+1) x F 0016 % Deriv.Tgig = derivative Tg w.r.t. ig; size ny x ny*(nig+1) x F 0017 % ig = reshape(permute(Theta.Ig, [2,1]), [ny*(nig+1),1]) 0018 % 0019 % Input parameters 0020 % 0021 % xMat = structure with tables of powers of (jwk)^r or (zk^-r) 0022 % xMat.Plant = plant model, size: F x max order 0023 % 0024 % PolyTrans = structure containing the polynomials and transfer functions evaluated in x 0025 % PolyTrans.A = denominator polynomial plant transfer function evaluated in x.Plant, size 1 x F 0026 % PolyTrans.G = plant transfer matrix evaluated in x.Plant, size ny x nu x F 0027 % PolyTrans.Tg = plant transient term evaluated in x.Plant, size ny x F 0028 % 0029 % ModelVar = contains the information about the model to be identified 0030 % structure with fields 'Transient', 'ThePlane', 'TheModel', 'Reciprocal', ... 0031 % ModelVar.Transient = 1 then the initial conditions of the plant and/or noise are estimated 0032 % ModelVar.PlantPlane = plane of the plant model 0033 % 's': continuous-time; 0034 % 'w': sqrt(s)-domain 0035 % 'z': discrete-time; 0036 % '': plane not defined 0037 % ModelVar.Struct = model structure 0038 % 'EIV': errors-in-variables (noisy input-output data) 0039 % 'OE': generalised output error (known input, noisy output) 0040 % ModelVar.RecipPlant = 1 if plant model is reciprocal: G(i,j) = G(j,i) 0041 % ModelVar.nu = number of inputs 0042 % ModelVar.ny = number of outputs 0043 % ModelVar.na = order polynomial A 0044 % ModelVar.nb = order matrix polynomial B 0045 % ModelVar.nig = order vector polynomial Ig 0046 % 0047 % 0048 % Copyright (c) Rik Pintelon, Vrije Universiteit Brussel - dept. ELEC, 27 November 2009 0049 % All rights reserved. 0050 % Software can be used freely for non-commercial applications only. 0051 % 0052 0053 Deriv = struct('vecGa', [], 'vecGb', [], 'Tga', [], 'Tgig', []); 0054 0055 F = size(xMat.Plant,1); 0056 na = ModelVar.na; 0057 nb = ModelVar.nb; 0058 nig = ModelVar.nig; 0059 ny = ModelVar.ny; 0060 nu = ModelVar.nu; 0061 0062 Deriv.vecGa = zeros(ny*nu, na+1, F); 0063 Deriv.vecGb = zeros(ny*nu, ny*nu*(nb+1), F); 0064 Deriv.Tga = zeros(ny, na+1, F); 0065 Deriv.Tgig = zeros(ny, ny*(nig+1), F); 0066 0067 % divide xMat.Plant by A-polynomial 0068 MaxOrder = size(xMat.Plant, 2); 0069 xMat.Plant = xMat.Plant./repmat(PolyTrans.A.',1,MaxOrder); 0070 0071 0072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0073 % Fast calculation of the derivative of vec(G) w.r.t. a. The lines below are equivalent with % 0074 % for kk = 1:F % 0075 % vecG = PolyTrans.G(:,:,kk); % 0076 % vecG = vecG(:); % 0077 % Deriv.vecGa(:,:,kk) = - vecG * xMat.Plant(kk, 1:na+1); % 0078 % end % 0079 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0080 0081 for ii = 1:nu*ny 0082 0083 column = ceil(ii/ny); 0084 row = ii - (column-1)*ny; 0085 % squeeze function on 1 x 1 x F delivers F x 1 !!! 0086 G = squeeze(PolyTrans.G(row, column, :)); 0087 Deriv.vecGa(ii,:,:) = -(xMat.Plant(:, 1:na+1) .* repmat(G, [1, na+1])).'; 0088 0089 end % ii 0090 0091 0092 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0093 % Fast calculation of the derivative of vec(G) w.r.t. b. The lines below are equivalent with % 0094 % for kk = 1:F % 0095 % Deriv.vecGb(:,:,kk) = kron(eye(nu*ny, nu*ny), xMat.Plant(kk, 1:nb+1)); % 0096 % end % 0097 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0098 0099 for ii = 1:nu*ny 0100 0101 vii = zeros(nu*ny, 1); 0102 vii(ii) = 1; 0103 Deriv.vecGb(ii,:,:) = kron(vii, (xMat.Plant(:, 1:nb+1)).'); 0104 0105 end % ii 0106 0107 0108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0109 % Fast calculation of the derivative Tg w.r.t. a. The lines below are equivalent with % 0110 % for kk = 1:F % 0111 % Deriv.Tga(:,:,kk) = - PolyTrans.Tg(:, kk) * xMat.Plant(kk, 1:na+1); % 0112 % end % 0113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0114 0115 for ii = 1:ny 0116 0117 Tg = PolyTrans.Tg(ii, :).'; 0118 Deriv.Tga(ii,:,:) = -(xMat.Plant(:, 1:na+1) .* repmat(Tg, [1, na+1])).'; 0119 0120 end % ii 0121 0122 0123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0124 % Fast calculation of the derivative of Tg w.r.t. ig. The lines below are equivalent with % 0125 % for kk = 1:F % 0126 % Deriv.Tgig(:,:,kk) = kron(eye(ny, ny), xMat.Plant(kk, 1:nig+1)); % 0127 % end % 0128 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0129 0130 for ii = 1:ny 0131 0132 vii = zeros(ny, 1); 0133 vii(ii) = 1; 0134 Deriv.Tgig(ii,:,:) = kron(vii, (xMat.Plant(:, 1:nig+1)).'); 0135 0136 end % ii 0137