TheJacob = MIMO_WGTLS_Jacob(data, xMat, ModelVar) Calculates the jacobian matrix w.r.t. ALL the plant and transient model parameters. The selection of the free model parameters, and the imposition of the model constraints (reciprocity) is done in the routine MIMO_ML_AddSelectColumns Output parameters TheJacob = jacobian matrix, size: ny x ntheta x F Input parameters data = structure containing the non-parametric data data.Y = DFT spectrum ny x 1 output signal, size: ny x F data.U = DFT spectrum nu x 1 input signal, size: nu x F data.freq = vector of frequency values (Hz), size: F x 1 data.Ts = sampling time (s) data.sqrtWinv = square root of the inverse of the weighting matrix W, size: ny x ny x F data.DC = 1 if DC present otherwise 0 data.Nyquist = 1 if Nyquist frequency present otherwise 0 xMat = structure with tables of powers of (jwk)^r or (zk^-r) xMat.Plant = plant model, size: F x max order 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 TheJacob = MIMO_WGTLS_Jacob(data, xMat, ModelVar); 0002 % 0003 % TheJacob = MIMO_WGTLS_Jacob(data, xMat, ModelVar) 0004 % 0005 % Calculates the jacobian matrix w.r.t. ALL the plant and transient model parameters. 0006 % The selection of the free model parameters, and the imposition of the model constraints 0007 % (reciprocity) is done in the routine MIMO_ML_AddSelectColumns 0008 % 0009 % 0010 % Output parameters 0011 % 0012 % TheJacob = jacobian matrix, size: ny x ntheta x F 0013 % 0014 % 0015 % Input parameters 0016 % 0017 % data = structure containing the non-parametric data 0018 % data.Y = DFT spectrum ny x 1 output signal, size: ny x F 0019 % data.U = DFT spectrum nu x 1 input signal, size: nu x F 0020 % data.freq = vector of frequency values (Hz), size: F x 1 0021 % data.Ts = sampling time (s) 0022 % data.sqrtWinv = square root of the inverse of the weighting matrix W, size: ny x ny x F 0023 % data.DC = 1 if DC present otherwise 0 0024 % data.Nyquist = 1 if Nyquist frequency present otherwise 0 0025 % 0026 % xMat = structure with tables of powers of (jwk)^r or (zk^-r) 0027 % xMat.Plant = plant model, size: F x max order 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 0033 % model 0034 % 's': continuous-time; 0035 % 'w': sqrt(s)-domain 0036 % 'z': discrete-time; 0037 % '': plane not defined 0038 % ModelVar.Struct = model structure 0039 % 'EIV': errors-in-variables (noisy input-output data) 0040 % 'OE': generalised output error (known input, noisy output) 0041 % ModelVar.RecipPlant = 1 if plant model is reciprocal: G(i,j) = G(j,i) 0042 % ModelVar.nu = number of inputs 0043 % ModelVar.ny = number of outputs 0044 % ModelVar.na = order polynomial A 0045 % ModelVar.nb = order matrix polynomial B 0046 % ModelVar.nig = order vector polynomial Ig 0047 % 0048 % 0049 % Copyright (c) Rik Pintelon, Vrije Universiteit Brussel - dept. ELEC, 27 November 2009 0050 % All rights reserved. 0051 % Software can be used freely for non-commercial applications only. 0052 % 0053 0054 % note that DC and Nyquist have a contribution 1/2 to the cost function 0055 % therefore the appropriate variables must be scaled by 1/sqrt(2) at DC 0056 % and Nyquist; this is already done for the variable Error 0057 0058 0059 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0060 % derivative prediction error w.r.t. ALL model parameters % 0061 % a = Theta.A(:) % 0062 % b = reshape(permute(Theta.B, [3,1,2]), [ny*nu*(nb+1),1]) % 0063 % ig = reshape(permute(Theta.Ig, [2,1]), [ny*(nig+1),1]) % 0064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0065 0066 % number of frequencies 0067 F = size(xMat.Plant,1); 0068 0069 % order polynomials 0070 na = ModelVar.na; 0071 nb = ModelVar.nb; 0072 nig = ModelVar.nig; 0073 0074 % number of outputs and inputs 0075 ny = ModelVar.ny; 0076 nu = ModelVar.nu; 0077 0078 % total number of model parameters 0079 ntheta = (na+1) + (nb+1)*nu*ny + (nig+1)*ny; 0080 0081 TheJacob = zeros(ny, ntheta, F); 0082 0083 Deriv.Aa = xMat.Plant(:, 1:na+1).'; % derivative A w.r.t. a 0084 0085 Hinv = data.sqrtWinv; 0086 0087 0088 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0089 % Fast calculation of the derivative of vec(B) w.r.t. b. The lines below are equivalent with % 0090 % for kk = 1:F % 0091 % Deriv.vecBb(:,:,kk) = kron(eye(nu*ny, nu*ny), xMat.Plant(kk, 1:nb+1)); % 0092 % end % 0093 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0094 0095 Deriv.vecBb = zeros(ny*nu, ny*nu*(nb+1), F); 0096 for ii = 1:nu*ny 0097 0098 vii = zeros(nu*ny, 1); 0099 vii(ii) = 1; 0100 Deriv.vecBb(ii,:,:) = kron(vii, (xMat.Plant(:, 1:nb+1)).'); 0101 0102 end % ii 0103 0104 0105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0106 % Fast calculation of the derivative of Ig w.r.t. ig. The lines below are equivalent with % 0107 % for kk = 1:F % 0108 % Deriv.Igig(:,:,kk) = kron(eye(ny, ny), xMat.Plant(kk, 1:nig+1)); % 0109 % end % 0110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0111 0112 Deriv.Igig = zeros(ny, ny*(nig+1), F); 0113 for ii = 1:ny 0114 0115 vii = zeros(ny, 1); 0116 vii(ii) = 1; 0117 Deriv.Igig(ii,:,:) = kron(vii, (xMat.Plant(:, 1:nig+1)).'); 0118 0119 end % ii 0120 0121 0122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0123 % Fast calculation of the derivative w.r.t. a. The lines below are equivalent with % 0124 % for kk = 1:F % 0125 % Low = 1; % 0126 % Upp = (na+1); % 0127 % TheJacob(:,Low:Upp,kk) = (Hinv(:,:,kk) * data.Y(:,kk)) * (Deriv.Aa(:,kk).'); % 0128 % end % 0129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0130 0131 % calculation of the derivative of the residual w.r.t. a for all frequencies 0132 DerivResa = zeros(ny,na+1,F); 0133 for ii = 1:ny 0134 dataY = data.Y(ii, :).'; 0135 DerivResa(ii,:,:) = (Deriv.Aa(1:na+1,:).' .* repmat(dataY, [1, na+1])).'; 0136 end % ii 0137 0138 % derivative w.r.t. a 0139 Low = 1; 0140 Upp = (na+1); 0141 for ii = 1:ny 0142 0143 Hinvii = squeeze(Hinv(ii,:,:)); 0144 if ny == 1 0145 Hinvii = Hinvii.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0146 end % if 0147 0148 for jj = Low:Upp 0149 0150 jk = jj-Low+1; 0151 DerivResajj = squeeze(DerivResa(:,jk,:)); 0152 if ny == 1 0153 DerivResajj = DerivResajj.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0154 end % if 0155 TheJacob(ii,jj,:) = sum(Hinvii.*DerivResajj, 1); 0156 0157 end %jj 0158 end % ii 0159 0160 0161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0162 % Fast calculation of the derivative w.r.t. b. The lines below are equivalent with % 0163 % for kk = 1:F % 0164 % Low = Upp+1; % 0165 % Upp = Low + (nb+1)*ny*nu - 1; % 0166 % Mat = kron(data.U(:,kk).', squeeze(Hinv(:,:,kk))); % 0167 % TheJacob(:,Low:Upp,kk) = - Mat * Deriv.vecBb(:,:,kk); % 0168 % end % 0169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0170 0171 % calculation of the matrix Mat for all frequencies 0172 Uii = zeros(1,1,F); 0173 Mat = zeros(ny, nu*ny, F); 0174 for ii = 1:nu 0175 Uii(1,1,:) = data.U(ii,:); 0176 columns = [(ii-1)*ny+1:ii*ny]; 0177 Mat(:, columns, :) = Hinv .* repmat(Uii, [ny, ny, 1]); 0178 end % ii 0179 0180 % derivative w.r.t. b 0181 Low = Upp+1; 0182 Upp = Low + (nb+1)*ny*nu - 1; 0183 for ii = 1:ny 0184 0185 Matii = squeeze(Mat(ii,:,:)); 0186 if ny*nu == 1 0187 Matii = Matii.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0188 end % if 0189 Hinvii = squeeze(Hinv(ii,:,:)); 0190 if ny == 1 0191 Hinvii = Hinvii.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0192 end % if 0193 0194 for jj = Low:Upp 0195 0196 jk = jj-Low+1; 0197 DerivvecBbjj = squeeze(Deriv.vecBb(:,jk,:)); 0198 if nu*ny == 1 0199 DerivvecBbjj = DerivvecBbjj.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0200 end % if 0201 TheJacob(ii,jj,:) = - sum(Matii.*DerivvecBbjj, 1); 0202 0203 end %jj 0204 end % ii 0205 0206 0207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0208 % Fast calculation of the derivative w.r.t. ig. The lines below are equivalent with % 0209 % for kk = 1:F % 0210 % Low = Upp+1; % 0211 % Upp = Low + (nig+1)*ny - 1; % 0212 % TheJacob(:,Low:Upp,kk) = - Hinv(:,:,kk) * Deriv.Igig(:,:,kk); % 0213 % end % 0214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0215 0216 % derivative w.r.t. ig 0217 Low = Upp+1; 0218 Upp = Low + (nig+1)*ny - 1; 0219 for ii = 1:ny 0220 0221 Hinvii = squeeze(Hinv(ii,:,:)); 0222 if ny == 1 0223 Hinvii = Hinvii.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0224 end % if 0225 0226 for jj = Low:Upp 0227 0228 jk = jj-Low+1; 0229 DerivIgigjj = squeeze(Deriv.Igig(:,jk,:)); 0230 if ny == 1 0231 DerivIgigjj = DerivIgigjj.'; % squeeze on 1 x 1 x F gives F x 1 !!! 0232 end % if 0233 TheJacob(ii,jj,:) = - sum(Hinvii.*DerivIgigjj, 1); 0234 0235 end %jj 0236 end % ii 0237 0238 % DC and Nyquist count for 1/sqrt(2) 0239 if data.DC == 1 0240 TheJacob(:,:,1) = TheJacob(:,:,1)/sqrt(2); 0241 end 0242 if data.Nyquist == 1 0243 TheJacob(:,:,end) = TheJacob(:,:,end)/sqrt(2); 0244 end