You are on page 1of 15

MATLAB CODE FOR NUMERICAL RELAY

clear all;
close all;
clc;
fprintf('VOLTAGE \n');
VoltagePeakValue1=input('PeakValue1=');
VoltagePhase1=input('Phase1=');
VoltagePeakValue2=input('PeakValue2=');
VoltagePhase2=input('Phase2=');
VoltagePeakValue3=input('PeakValue3=');
VoltagePhase3=input('Phase3=');
fprintf('CURRENTS \n');
CurrentPeakValue1=input('PeakValue1=');
CurrentPhase1=input('Phase1=');
CurrentPeakValue2=input('PeakValue2=');
CurrentPhase2=input('Phase2=');
CurrentPeakValue3=input('PeakValue3=');
CurrentPhase3=input('Phase3=');
f=50;
t=0:0.00001:0.2;
a=cos(2*pi/3)+j*sin(2*pi/3);
w = 2 * pi * f; % Angular frequency in rad/sec
Va=VoltagePeakValue1*0.707*(cos(w*t+VoltagePhase1*pi/180)+ i*sin(w*t+VoltagePhase1*pi/180));
Vb=VoltagePeakValue2*0.707*(cos(w*t+VoltagePhase2*pi/180)+i*sin(w*t+VoltagePhase2*pi/180));
Vc=VoltagePeakValue3*0.707*(cos(w*t+VoltagePhase3*pi/180)+i*sin(w*t+VoltagePhase3*pi/180));
Ia=CurrentPeakValue1*0.707*(cos(w*t+CurrentPhase1*pi/180)+ i*sin(w*t+CurrentPhase1*pi/180));
Ib=CurrentPeakValue2*0.707*(cos(w*t+CurrentPhase2*pi/180)+i*sin(w*t+CurrentPhase2*pi/180));
Ic=CurrentPeakValue3*0.707*(cos(w*t+CurrentPhase3*pi/180)+i*sin(w*t+CurrentPhase3*pi/180));
figure(1);
hold on;
plot(t,Va,'r',t,Vb,'y',t,Vc,'b');
xlim([0 .02]);
xlabel('Time(t)');ylim([-300 300]);
ylabel('Voltage(I)');
title('3-Phase Voltages');
legend('Va','Vb','Vc');
grid;
V0=1/3*(Va+Vb+Vc);
V1=1/3*(Va+a*Vb+a^2*Vc);
V2=1/3*(Va+a^2*Vb+a*Vc);

figure(2);
hold on;
subplot(3,1,1),plot(t,V0,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
title('\bfZero Sequence');
subplot(3,1,2),plot(t,V1,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
title('\bfPositive Sequence');
subplot(3,1,3),plot(t,V2,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in volts');
title('\bfNegative Sequence');
figure(3);
hold on;
plot(t,Ia,'r',t,Ib,'y',t,Ic,'b');
xlim([0 .02]);
xlabel('Time(t)');ylim([-300 300]);
ylabel('Current(I)');
title('3-Phase Currents');
legend('Ia','Ib','Ic');
grid;
I0=1/3*(Ia+Ib+Ic);
I1=1/3*(Ia+a*Ib+a^2*Ic);
I2=1/3*(Ia+a^2*Ib+a*Ic);
figure(4);
subplot(3,1,1),plot(t,I0,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in amps');
title('\bfZero Sequence');
subplot(3,1,2),plot(t,I1,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in amps');
title('\bfPositive Sequence');
subplot(3,1,3),plot(t,I2,'black')
ylim([-300 300]);
xlabel('\bfTime in sec');
ylabel('\bfAmplitude in amps');
title('\bfNegative Sequence');

Va0=V0;
Vb0=V0;
Vc0=V0;
Va1=V1;
Vb1=a^2*Va1;
Vc1=a*Va1;
Va2=V2;
Vb2=a*Va2;
Vc2=a^2*Va2;
Ia0=I0;
Ib0=I0;
Ic0=I0;
Ia1=I1;
Ib1=a^2*Ia1;
Ic1=a*Ia1;
Ia2=I2;
Ib2=a*Ia2;
Ic2=a^2*Ia2;
%3-Phase Fault
if(((radtodeg(angle(V1(1)))-radtodeg(angle(I1(1))))>=90)&& (floor(abs(V0(1)))==0)&&
(floor(abs(V2(1)))==0))
fprintf ('\n 3-Phase Fault \n');
else
fprintf ('\n');
end
%Line to Line fault
if(((radtodeg(angle(V1(1)))-radtodeg(angle(I1(1))))>=90)&&
(floor(abs(V0(1)))==0)&&(floor(abs(V2(1)))~=0))
fprintf ('\nLine to Line Fault \n');
else
fprintf (' \n');
end
%Line to Line to Ground Fault
if(((radtodeg(angle(V1(1)))-radtodeg(angle(I1(1))))>=90)&&(floor(abs(V0(1)))~=0) &&
(floor(abs(V2(1)))~=0))
fprintf ('\nLine to Line to Ground Fault \n');
else
fprintf ('\n');
end

%Line to Ground Fault


if(((radtodeg(angle(V1(1)))-radtodeg(angle(V2(1))))==180)&&(floor(abs(V0(1)))~=0) &&
(floor(abs(V2(1)))~=0))
fprintf ('\nLine to Ground Fault \n');
else
fprintf ('\n');
end
%Balanced
if((floor(radtodeg(angle(V1(1)))-radtodeg(angle(I1(1))))<=30)&& (floor(abs(V0(1)))==0)&&
(floor(abs(V2(1)))==0))
fprintf ('\n Balanced condition \n');
else
fprintf ('\n');
end
figure(5)
grid on;
hold on;
plot([0 real(Va0(1))],[0 imag(Va0(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Va0(1)),imag(Va0(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Vb0(1))],[0 imag(Vb0(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Vb0(1)),imag(Vb0(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Vc0(1))],[0 imag(Vc0(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Vc0(1)),imag(Vc0(1)),'md','MarkerFaceColor','m'); %Add filled diamond.
hold on;
title('Voltage Phasors');
legend('Zero Sequence Voltages','location','North');
hold off
figure(6)
grid on;
hold on;
plot([0 real(Va1(1))],[0 imag(Va1(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Va1(1)),imag(Va1(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Vb1(1))],[0 imag(Vb1(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Vb1(1)),imag(Vb1(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Vc1(1))],[0 imag(Vc1(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Vc1(1)),imag(Vc1(1)),'md','MarkerFaceColor','m'); %Add filled diamond.
hold on;
title('Voltage Phasors');
legend('+ve Sequence Voltages','location','North');

hold off
figure(7)
grid on;
hold on;
plot([0 real(Va2(1))],[0 imag(Va2(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Va2(1)),imag(Va2(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Vb2(1))],[0 imag(Vb2(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Vb2(1)),imag(Vb2(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Vc2(1))],[0 imag(Vc2(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Vc2(1)),imag(Vc2(1)),'md','MarkerFaceColor','m'); %Add filled diamond.
hold on;
title('Voltage Phasors');
legend('-ve Sequence Voltages','location','North');
hold off
figure(8)
grid on;
hold on;
plot([0 real(Ia0(1))],[0 imag(Ia0(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Ia0(1)),imag(Ia0(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Ib0(1))],[0 imag(Ib0(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Ib0(1)),imag(Ib0(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Ic0(1))],[0 imag(Ic0(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Ic0(1)),imag(Ic0(1)),'md','MarkerFaceColor','m'); %Add filled diamond.
hold on;
title('Voltage Phasors');
legend('Zero Sequence Currents','location','North');
hold off
figure(9)
grid on;
hold on;
plot([0 real(Ia1(1))],[0 imag(Ia1(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Ia1(1)),imag(Ia1(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Ib1(1))],[0 imag(Ib1(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Ib1(1)),imag(Ib1(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Ic1(1))],[0 imag(Ic1(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Ic1(1)),imag(Ic1(1)),'md','MarkerFaceColor','m'); %Add filled diamond.

hold on;
title('Voltage Phasors');
legend('+ve Sequence Currents','location','North');
hold off
figure(10)
grid on;
hold on;
plot([0 real(Ia2(1))],[0 imag(Ia2(1))],'g','LineWidth',2); %phasor w/o mark at end.
plot(real(Ia2(1)),imag(Ia2(1)),'gd','MarkerFaceColor','g'); %Add filled diamond.
axis([-360 360 -360 360]);
hold on;
plot([0 real(Ib2(1))],[0 imag(Ib2(1))],'b','LineWidth',2); %phasor w/o mark at end.
plot(real(Ib2(1)),imag(Ib2(1)),'bd','MarkerFaceColor','b'); %Add filled diamond.
hold on;
plot([0 real(Ic2(1))],[0 imag(Ic2(1))],'m','LineWidth',2); %phasor w/o mark at end.
plot(real(Ic2(1)),imag(Ic2(1)),'md','MarkerFaceColor','m'); %Add filled diamond.
hold on;
title('Voltage Phasors');
legend('-ve Sequence Currents','location','North');
hold off

LINE TO GROUND FAULT


LINE TO GROUND FAULT AT PHASE A (A,G)

PHASE VOLTAGES AND CURRENT

SEQUENCE VOLTAGES

SEQUENCE CURRENTS

LINE TO GROUND FAULT AT PHASE B (B,G)

SEQUENCE VOLTAGES

SEQUENCE CURRENTS

LINE TO GROUND FAULT AT PHASE C (C,G)

PHASE VOLTAGES AND CURRENT

SEQUENCE VOLTAGES

SEQENCE CURRENTS

DOUBLE LINE TO GROUND FAULT


DOUBLE LINE TO GROUND FAULT ON PHASE A & B (A,B,G)

PHASE VOLTAGES AND CURRENT

SEQUENCE VOLTAGES

SEQENCE CURRENTS

DOUBLE LINE TO GROUND FAULT ON PHASE B & C (B,C,G)

PHASE VOLTAGES AND CURRENT

SEQUENCE VOLTAGES

SEQENCE CURRENTS

DOUBLE LINE TO GROUND FAULT ON PHASE C & A (C,A,G)

PHASE VOLTAGES AND CURRENT

SEQUENCE VOLTAGES

SEQENCE CURRENTS

You might also like