0001 function [V, converged, i] = state_est(branch, Ybus, Yf, Yt, Sbus, V0, ref, pv, pq, mpopt)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0038 TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0039 ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0040
0041
0042 if nargin < 10
0043 mpopt = mpoption;
0044 end
0045
0046
0047 tol = mpopt(2);
0048 max_it = mpopt(3);
0049 verbose = mpopt(31);
0050
0051
0052 converged = 0;
0053 i = 0;
0054 nb = length(V0);
0055 nbr = size(Yf, 1);
0056 nref = [pv;pq];
0057 f = branch(:, F_BUS);
0058 t = branch(:, T_BUS);
0059
0060
0061 [dSbus_dVm, dSbus_dVa] = dSbus_dV(Ybus, V0);
0062 [dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, Sf, St] = dSbr_dV(branch, Yf, Yt, V0);
0063 H = [
0064 real(dSf_dVa) real(dSf_dVm);
0065 real(dSt_dVa) real(dSt_dVm);
0066 real(dSbus_dVa) real(dSbus_dVm);
0067 speye(nb) sparse(nb,nb);
0068 imag(dSf_dVa) imag(dSf_dVm);
0069 imag(dSt_dVa) imag(dSt_dVm);
0070 imag(dSbus_dVa) imag(dSbus_dVm);
0071 sparse(nb,nb) speye(nb);
0072 ];
0073
0074
0075 z = [
0076 real(Sf);
0077 real(St);
0078 real(Sbus);
0079 angle(V0);
0080 imag(Sf);
0081 imag(St);
0082 imag(Sbus);
0083 abs(V0);
0084 ];
0085
0086
0087 fullscale = 30;
0088 sigma = [
0089 0.02 * abs(Sf) + 0.0052 * fullscale * ones(nbr,1);
0090 0.02 * abs(St) + 0.0052 * fullscale * ones(nbr,1);
0091 0.02 * abs(Sbus) + 0.0052 * fullscale * ones(nb,1);
0092 0.2 * pi/180 * 3*ones(nb,1);
0093 0.02 * abs(Sf) + 0.0052 * fullscale * ones(nbr,1);
0094 0.02 * abs(St) + 0.0052 * fullscale * ones(nbr,1);
0095 0.02 * abs(Sbus) + 0.0052 * fullscale * ones(nb,1);
0096 0.02 * abs(V0) + 0.0052 * 1.1 * ones(nb,1);
0097 ] ./ 3;
0098 ns = length(sigma);
0099 W = sparse(1:ns, 1:ns , sigma .^ 2, ns, ns );
0100 WInv = sparse(1:ns, 1:ns , 1 ./ sigma .^ 2, ns, ns );
0101
0102
0103
0104
0105
0106 err = normrnd( zeros(size(sigma)), sigma );
0107
0108
0109
0110
0111 z = z + err;
0112
0113
0114 V = ones(nb,1);
0115
0116
0117 Sfe = V(f) .* conj(Yf * V);
0118 Ste = V(t) .* conj(Yt * V);
0119 Sbuse = V .* conj(Ybus * V);
0120 z_est = [
0121 real(Sfe);
0122 real(Ste);
0123 real(Sbuse);
0124 angle(V);
0125 imag(Sfe);
0126 imag(Ste);
0127 imag(Sbuse);
0128 abs(V);
0129 ];
0130
0131
0132 delz = z - z_est;
0133 normF = delz' * WInv * delz;
0134 chusqu = err' * WInv * err;
0135
0136
0137 if verbose > 1
0138 fprintf('\n it norm( F ) step size');
0139 fprintf('\n---- -------------- --------------');
0140 fprintf('\n%3d %10.3e %10.3e', i, normF, 0);
0141 end
0142 if normF < tol
0143 converged = 1;
0144 if verbose > 1
0145 fprintf('\nConverged!\n');
0146 end
0147 end
0148
0149
0150
0151
0152
0153 vv=[(3:nbr), ...
0154 (nbr+1:2*nbr), ...
0155 (2*nbr+2:2*nbr+nb), ...
0156 (2*nbr+nb+2:2*nbr+2*nb), ...
0157 (2*nbr+2*nb+3:3*nbr+2*nb), ...
0158 (3*nbr+2*nb+1:4*nbr+2*nb), ...
0159 (4*nbr+2*nb+2:4*nbr+3*nb), ...
0160 (4*nbr+3*nb+2:4*nbr+4*nb)]';
0161
0162 ww = [ nref; nb+nref ];
0163
0164
0165 one_at_a_time = 1; max_it_bad_data = 50;
0166
0167 ibd = 1;
0168 while (~converged && ibd <= max_it_bad_data)
0169 nm = length(vv);
0170 baddata = 0;
0171
0172
0173 HH = H(vv,ww);
0174 WWInv = WInv(vv,vv);
0175 ddelz = delz(vv);
0176 VVa = angle(V(nref));
0177 VVm = abs(V(nref));
0178
0179
0180
0181
0182
0183
0184
0185 max_it = 100;
0186 i = 0;
0187 while (~converged && i < max_it)
0188
0189 i = i + 1;
0190
0191
0192 F = HH' * WWInv * ddelz;
0193 J = HH' * WWInv * HH;
0194 dx = (J \ F);
0195
0196
0197 VVa = VVa + dx(1:nb-1);
0198 VVm = VVm + dx(nb:2*nb-2);
0199 V(nref) = VVm .* exp(1j * VVa);
0200
0201
0202 Sfe = V(f) .* conj(Yf * V);
0203 Ste = V(t) .* conj(Yt * V);
0204 Sbuse = V .* conj(Ybus * V);
0205 z_est = [
0206 real(Sfe);
0207 real(Ste);
0208 real(Sbuse);
0209 angle(V);
0210 imag(Sfe);
0211 imag(Ste);
0212 imag(Sbuse);
0213 abs(V);
0214 ];
0215
0216
0217 delz = z - z_est;
0218 ddelz = delz(vv);
0219 normF = ddelz' * WWInv * ddelz;
0220
0221
0222 step = dx' * dx;
0223 if verbose > 1
0224 fprintf('\n%3d %10.3e %10.3e', i, normF, step);
0225 end
0226 if (step < tol)
0227 converged = 1;
0228 if verbose
0229 fprintf('\nState estimator converged in %d iterations.\n', i);
0230 end
0231 end
0232 end
0233 if verbose
0234 if ~converged
0235 fprintf('\nState estimator did not converge in %d iterations.\n', i);
0236 end
0237 end
0238
0239
0240 B = zeros(nm,1);
0241 bad_threshold = 6.25;
0242 RR = inv(WWInv) - 0.95 * HH * inv(HH' * WWInv * HH) * HH';
0243
0244
0245
0246 rr = diag(RR);
0247
0248 B = ddelz .^ 2 ./ rr;
0249 [maxB,i_maxB] = max(B);
0250 if one_at_a_time
0251 if maxB >= bad_threshold
0252 rejected = i_maxB;
0253 else
0254 rejected = [];
0255 end
0256 else
0257 rejected = find( B >= bad_threshold );
0258 end
0259 if length(rejected)
0260 baddata = 1;
0261 converged = 0;
0262 if verbose
0263 fprintf('\nRejecting %d measurement(s) as bad data:\n', length(rejected));
0264 fprintf('\tindex\t B\n');
0265 fprintf('\t-----\t-------------\n');
0266 fprintf('\t%4d\t%10.2f\n', [ vv(rejected), B(rejected) ]' );
0267 end
0268
0269
0270 k = find( B < bad_threshold );
0271 vv = vv(k);
0272 nm = length(vv);
0273 end
0274
0275 if (baddata == 0)
0276 converged = 1;
0277 if verbose
0278 fprintf('\nNo remaining bad data, after discarding data %d time(s).\n', ibd-1);
0279 fprintf('Largest value of B = %.2f\n', maxB);
0280 end
0281 end
0282 ibd = ibd + 1;
0283 end