Revised Main
Revised Main
close all
%There are a total of three functions that are called upon in this script.
%using the transmission line parameter values. It also adds noise to the
%for every parameter. This information is passed back to the script for
%plotting purposes
%BEGIN-----------------------------------------------------------------
----
num_est = 1;
num_meas = 500;
type = 1;
% PSD = (0:0.001:0.02)';
PSD = 0;
%1 = VS %2 = IS %3 = VR %4 = IR
%5 = ALL
pick = 5;
write = 2;
Shi_R = zeros(num_est,6);
Shi_X = zeros(num_est,6);
Shi_B = zeros(num_est,6);
Lowe_R = zeros(num_est,6);
Lowe_X = zeros(num_est,6);
Lowe_B = zeros(num_est,6);
Shi_PDR = zeros(length(PSD),6);
Shi_PDX = zeros(length(PSD),6);
Shi_PDB = zeros(length(PSD),6);
Lowe_PDR = zeros(length(PSD),6);
Lowe_PDX = zeros(length(PSD),6);
Lowe_PDB = zeros(length(PSD),6);
detmn = zeros(length(PSD),1);
%ESTIMATE--------------------------------------------------------------
------
for m = 1:length(PSD)
end
for e = 1:num_est
k = 0; %counter variable
X = zeros(num_meas*6,36);
Y = zeros(num_meas*6,1);
S = zeros(num_meas*12,18);
W = zeros(num_meas*12,1);
end
for n = 1:num_meas
Var = VabcR(n,1);
Vbr = VabcR(n,2);
Vcr = VabcR(n,3);
Iar = IabcR(n,1);
Ibr = IabcR(n,2);
Icr = IabcR(n,3);
Vas = VabcS(n,1);
Vbs = VabcS(n,2);
Vcs = VabcS(n,3);
Shi_R = zeros(num_est,6);
Shi_X = zeros(num_est,6);
Shi_B = zeros(num_est,6);
Lowe_R = zeros(num_est,6);
Lowe_X = zeros(num_est,6);
Lowe_B = zeros(num_est,6);
Shi_PDR = zeros(length(PSD),6);
Shi_PDX = zeros(length(PSD),6);
Shi_PDB = zeros(length(PSD),6);
Lowe_PDR = zeros(length(PSD),6);
Lowe_PDX = zeros(length(PSD),6);
Lowe_PDB = zeros(length(PSD),6);
detmn = zeros(length(PSD),1);
end
%ESTIMATE--------------------------------------------------------------
------
for m = 1:length(PSD)
end
for e = 1:num_est
k = 0; %counter variable
X = zeros(num_meas*6,36);
Y = zeros(num_meas*6,1);
S = zeros(num_meas*12,18);
W = zeros(num_meas*12,1);
end
for n = 1:num_meas
Var = VabcR(n,1);
Vbr = VabcR(n,2);
Vcr = VabcR(n,3);
Iar = IabcR(n,1);
Ibr = IabcR(n,2);
Icr = IabcR(n,3);
Vas = VabcS(n,1);
Vbs = VabcS(n,2);
Vcs = VabcS(n,3);
Ias = IabcS(n,1);
Ibs = IabcS(n,2);
Ics = IabcS(n,3);
%(Lowe Method)
index1 = 1 + k*6;
index2 = 2 + k*6;
index3 = 3 + k*6;
index4 = 4 + k*6;
index5 = 5 + k*6;
index6 = 6 + k*6;
ind1 = 1 + k*12;
ind2 = 2 + k*12;
ind3 = 3 + k*12;
ind4 = 4 + k*12;
ind5 = 5 + k*12;
ind6 = 6 + k*12;
ind7 = 7 + k*12;
ind8 = 8 + k*12;
ind9 = 9 + k*12;
ind10 = 10 + k*12;
ind11 = 11 + k*12;
ind12 = 12 + k*12;
X(index2,:) = [zeros(1,3) Var Vbr Vcr zeros(1,6) Iar Ibr Icr zeros(1,21)];
X(index3,:) = [zeros(1,6) Var Vbr Vcr zeros(1,6) Iar Ibr Icr zeros(1,18)];
X(index4,:) = [zeros(1,18) Var Vbr Vcr zeros(1,6) Iar Ibr Icr zeros(1,6)];
X(index5,:) = [zeros(1,21) Var Vbr Vcr zeros(1,6) Iar Ibr Icr zeros(1,3)];
Y(index1,1) = Vas;
Y(index2,1) = Vbs;
Y(index3,1) = Vcs;
Y(index4,1) = Ias;
Y(index5,1) = Ibs;
Y(index6,1) = Ics;
S(ind6,:) = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - imag(Vcr)/2 -
imag(Vcs)/2, 0, - imag(Var)/2 - imag(Vas)/2, - imag(Vbr)/2 - imag(Vbs)/2];
W(ind1,1) = real(Iar);
W(ind2,1) = real(Ibr);
W(ind3,1) = real(Icr);
W(ind7,1) = imag(Iar);
W(ind8,1) = imag(Ibr);
W(ind9,1) = imag(Icr);
%increment counter
k = k+1;
end
%Lowe
Method--------------------------------------------------------------
beta = X\Y;
A1 = beta(1,1);
A2 = beta(2,1);
A3 = beta(3,1);
A4 = beta(4,1);
A5 = beta(5,1);
A6 = beta(6,1);
A7 = beta(7,1);
A8 = beta(8,1);
A9 = beta(9,1);
B1 = beta(10,1);
B2 = beta(11,1);
B3 = beta(12,1);
B4 = beta(13,1);
B5 = beta(14,1);
B6 = beta(15,1);
B7 = beta(16,1);
B8 = beta(17,1);
B9 = beta(18,1);
C1 = beta(19,1);
C2 = beta(20,1);
C3 = beta(21,1);
C4 = beta(22,1);
C5 = beta(23,1);
C6 = beta(24,1);
C7 = beta(25,1);
C8 = beta(26,1);
C9 = beta(27,1);
D1 = beta(28,1);
D2 = beta(29,1);
D3 = beta(30,1);
D4 = beta(31,1);
D5 = beta(32,1);
D6 = beta(33,1);
D7 = beta(34,1);
D8 = beta(35,1);
D9 = beta(36,1);
A = [A1 A2 A3;
A4 A5 A6;
A7 A8 A9];
B = [B1 B2 B3;
B4 B5 B6;
B7 B8 B9];
C = [C1 C2 C3;
C4 C5 C6;
C7 C8 C9];
D = [D1 D2 D3;
D4 D5 D6;
D7 D8 D9];
Zabc_Lowe = B;
Za = B1;
Zb = B5;
Zc = B9;
Zab = B2;
Zac = B3;
Zbc = B6;
%Di-Shi
Method-------------------------------------------------------------
theta = (S'*S)\(S'*W);
Ga = theta(1,1);
Ta = theta(2,1);
Gb = theta(3,1);
Tb = theta(4,1);
Gc = theta(5,1);
Tc = theta(6,1);
Gab = theta(7,1);
Tab = theta(8,1);
Gac = theta(9,1);
Tac = theta(10,1);
Gbc = theta(11,1);
Tbc = theta(12,1);
Ba = theta(13,1);
Bb = theta(14,1);
Bc = theta(15,1);
Bab = theta(16,1);
Bac = theta(17,1);
Bbc = theta(18,1);
ya = Ga + 1i*Ta;
yb = Gb + 1i*Tb;
yc = Gc + 1i*Tc;
yab yb ybc;
Zabc_Shi = inv(yp);
Bab Bb Bbc;
Zabc_Shi(1,2);Zabc_Shi(1,3);Zabc_Shi(2,3)];
Yabc_Shi(1,2);Yabc_Shi(1,3);Yabc_Shi(2,3)];
Zabc_Lowe(1,2);Zabc_Lowe(1,3);Zabc_Lowe(2,3)];
Yabc_Lowe(1,2);Yabc_Lowe(1,3);Yabc_Lowe(2,3)];
Shi_R(e,:) = transpose(real(Result_Shi_Z));
Shi_X(e,:) = transpose(imag(Result_Shi_Z));
Shi_B(e,:) = transpose(imag(Result_Shi_Y));
Lowe_R(e,:) = transpose(real(Result_Lowe_Z));
Lowe_X(e,:) = transpose(imag(Result_Lowe_Z));
Lowe_B(e,:) = transpose(imag(Result_Lowe_Y));
deter(e,1) = det(ABCD);
[meanS, meanL, stdS, stdL, pdS, pdL] = analyze(Shi_R, Shi_X, Shi_B, Lowe_R,
Lowe_X, Lowe_B);
Shi_PDR(m,:) = pdS(1,:);
Shi_PDX(m,:) = pdS(2,:);
Shi_PDB(m,:) = pdS(3,:);
Lowe_PDR(m,:) = pdL(1,:);
Lowe_PDX(m,:) = pdL(2,:);
Lowe_PDB(m,:) = pdL(3,:);
detmn(m,1) = mean(deter);
disp(m)
%plot------------------------------------------------------------------
---
if type ~= 3
lw = 2.25;
if pick == 1
elseif pick == 2
elseif pick == 3
elseif pick == 4
elseif pick == 5
end
figure(1);
subplot(3,2,1)
hold all
grid on
xlabel(xtitle)
ylabel('Error of R (%)')
plot(PSD,Shi_PDR(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Shi_PDR(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Shi_PDR(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Shi_PDR(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Shi_PDR(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Shi_PDR(:,6),'LineWidth',lw,'Color','k')
%legend('Ra','Rb','Rc','Rab','Rac','Rbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
subplot(3,2,3)
hold all
grid on
xlabel(xtitle)
ylabel('Error of X (%)')
plot(PSD,Shi_PDX(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Shi_PDX(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Shi_PDX(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Shi_PDX(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Shi_PDX(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Shi_PDX(:,6),'LineWidth',lw,'Color','k')
%legend('Xa','Xb','Xc','Xab','Xac','Xbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
subplot(3,2,5)
hold all
grid on
xlabel(xtitle)
ylabel('Error of B (%)')
plot(PSD,Shi_PDB(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Shi_PDB(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Shi_PDB(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Shi_PDB(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Shi_PDB(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Shi_PDB(:,6),'LineWidth',lw,'Color','k')
%legend('Ba','Bb','Bc','Bab','Bac','Bbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
subplot(3,2,2)
hold all
grid on
xlabel(xtitle)
ylabel('Error of R (%)')
plot(PSD,Lowe_PDR(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Lowe_PDR(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Lowe_PDR(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Lowe_PDR(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Lowe_PDR(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Lowe_PDR(:,6),'LineWidth',lw,'Color','k')
%legend('Ra','Rb','Rc','Rab','Rac','Rbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
subplot(3,2,4)
hold all
grid on
xlabel(xtitle)
ylabel('Error of X (%)')
plot(PSD,Lowe_PDX(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Lowe_PDX(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Lowe_PDX(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Lowe_PDX(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Lowe_PDX(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Lowe_PDX(:,6),'LineWidth',lw,'Color','k')
%legend('Xa','Xb','Xc','Xab','Xac','Xbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
subplot(3,2,6)
hold all
grid on
xlabel(xtitle)
ylabel('Error of B (%)')
plot(PSD,Lowe_PDB(:,1),'LineWidth',lw,'Color','r')
plot(PSD,Lowe_PDB(:,2),'LineWidth',lw,'Color','g')
plot(PSD,Lowe_PDB(:,3),'LineWidth',lw,'Color','b')
plot(PSD,Lowe_PDB(:,4),'LineWidth',lw,'Color','c')
plot(PSD,Lowe_PDB(:,5),'LineWidth',lw,'Color','m')
plot(PSD,Lowe_PDB(:,6),'LineWidth',lw,'Color','k')
%legend('Ba','Bb','Bc','Bab','Bac','Bbc')
set(gca,'XMinorTick','on','YMinorTick','on')
%set(legend,'Location','EastOutside')
%write to excel
if type == 1
filename = 'bias_noise.xlsx';
elseif type == 2
filename = 'random_noise.xlsx';
end
if write == 1
xlswrite(filename,data,pick)
elseif write == 2
end
%----------------------------------------------------------------------
---
else
end