function [location_fault,err]=fault(Iaa,Ibb,Icc)
coder.extrinsic('wrcoef');
coder.extrinsic('legend');
coder.extrinsic('num2str');
coder.extrinsic('get_param');
coder.extrinsic('str2num');
coder.extrinsic('findpeaks');
coder.extrinsic('sortrows');
persistent d;
persistent di;
double location;
char actual_fault;
double locs;
double k;
double er;
double td;
double c;
b=([1/sqrt(3) 1/sqrt(3) 1/sqrt(3)
sqrt(2/3) -1/sqrt(6) -1/sqrt(6)
0 1/sqrt(2) -1/sqrt(2)]);
IM=b*[Iaa Ibb Icc]';
Ig=IM(1,:);
Ia1=IM(2,:);
signal=Ig;
signal_length=length(signal);
di=[];
[c,l] = wavedec(signal',3,'db5');
for i=1:3
cd=wrcoef('d',c,l,'db5',i);
di=[di;cd'];
end
k=0;
for i=3:-1:1;
k=k+1;
d(k,:)=di(i,:);
end
a=wrcoef('a',c,l,'db5',3);
MulDWT=[a';d];
details_1=d;
signal=Ia1;
signal_length1=length(signal);
di=[];
[c,l] = wavedec(signal',3,'db5');
for i=1:3
cd=wrcoef('d',c,l,'db5',i);
di=[di;cd'];
end
k=0;
for i=3:-1:1;
k=k+1;
d(k,:)=di(i,:);
end
a=wrcoef('a',c,l,'db5',3);
MulDWT=[a';d];
details_2=d;
details_2(1,end-40:end)=0;
[pks,locs] = findpeaks(details_2(1,:));
data=[pks',locs'];
[k]=sortrows(data,-1);
td=k(2,2)-k(1,2);
location=((2.89*10^5)*td*10^-6)/2;
disp(['Fault Location = ' num2str(location) ' km']) ;
actual_fault=get_param('two_remotes/Distributed Parameters Line','Length');
k=str2num(actual_fault);
er=abs(location-k);
location_fault=location;
err=er;
end