%*************************************************************************
%%This fucntion will store transducer coordinates and differences of
%%arrival times between each transducer and transducer 1,
%the arrival times are aquired via graphData() and is an input broyden() to solve for the
% signal location and travel time to transducer 1, adding the difference in
% arrival time of each transducer to this travel time yields the travel
% time
%%
%**************************************************************************
function [fun] = eqns(u)%unknown values are input parameters
%the pop rock falls vertically and so xs = zs = 0 and we assume the center
%of the borehole is at y = 0
xs = 0;
zs = 0;
%Transducer 1 and 2 locations in meters based on 3D print sample with a
%fracture 1/3 of the sample height
xt1 = -0.05;
yt1 = 0.015;
zt1 = -0.015;
xt2 = -0.05;
yt2 = 0.015;
zt2 = 0.015;
xt3 = -0.05;
yt3 = -.005;
zt3 = -0.015;
v = 2500;% wave speed in material determined by AST and distance formula
%differnce in arrival time between tranducer 1 and transducer 2;
% acquire locations of first peaks in transducers 1 and 2
File_names = dir('*.csv'); %attain every waveform in the event folder
%get files of interest, in this case those of transducer 1 and 2
file1 = File_names(3).name;
file2 = File_names(4).name;
file2 = File_names(5).name;
plus1 = 1; %offset y values
plus2 = 2;
plus3 = 3;
hold on
% %prof requested the dts so I need all the first peak locations
% numFiles = length(File_names);
% incr = 1:numFiles;
% for i = 1:numFiles %call graphData() for each waveform
% file = File_names(i).name;
% hold on
% plus = incr(i);%needed to offset graphs for plotting
% [p,l] = graphData(file,plus);
%
%
% end
[p1,l1] = graphData(file1,plus1);
% (ORIGINAL CODE IS COMMENTED OUT FOR NOW TO GET ALL
% DTS FROM EVENT 1)
% L1 = l1;
[p2,l2] = graphData(file2,plus2);
[p3,l3] = graphData(file2,plus2);
% L2 = l2;
% graphData() gives me locations on the first peak but I only require one of
% them
% maxL1 = max(L1);
%
% maxL2 = max(L2);
%multiply each location by the sample interval, 1*10^-7 to get the arrival
%times for transducers 1 and 2
art1 = l1*1e-7;
art2 = l2*1e-7;
art3 = l3*1e-7;
%
% tran10= 1038*1e-7;
%
% tran13 = 1019*1e-7;
%
% tran1 = 1047*1e-7;
%
% tran2 = 1054*1e-7;
%
% tran3 = 1038*1e-7;
%
% tran5 = 1048*1e-7;
%
% tran6 = 1042*1e-7;
%
% tran8= 1022*1e-7;
%
% tran9 = 1034*1e-7;
%
% dt10 = tran10 - tran1;
% dt13 = tran13 -tran1;
% dt1 = tran1- tran1;
% dt2 = tran2- tran1;
% dt3 = tran3- tran1;
% dt5 = tran5- tran1;
% dt6 = tran6- tran1;
% dt8 = tran8- tran1;
% dt9 = tran9 - tran1;
%deltat1 is clearly zero
deltat2 = art2 - art1;
deltat3 = art3 - art1;
% deltat2 = 7e-7;
ys = u(1); %source location and travel time from source to transducer 1
% are unkown and will be guessed initally with values of
% [0.5;2e-5] as input argumnents to eqns()
ts = u(2);
%non-linear system of equations, the first is for transducer 1 and the
%second is for transducer 2
fun(1,1) = (sqrt((xt1- xs)^2 + (yt1 - ys)^2 + (zt1 - zs)^2)/v )- (ts);
fun(2,1) = (sqrt((xt2- xs)^2 + (yt2 - ys)^2 + (zt2 - zs)^2)/v) - (ts - deltat2);
fun(3,1) = (sqrt((xt3- xs)^2 + (yt3 - ys)^2 + (zt3 - zs)^2)/v) - (ts - deltat3);
end
%end of eqns()*************************************************************