clear all
close all

ref=load('refer.txt');
sam=load('l-ansuan ni.txt');
time=ref(1:247,1); 
time=(time-time(1))*2./3e11;
ref=ref(1:247,2); 
ref=ref-mean(ref);
sam=sam(1:247,2); 
sam=sam-mean(sam);
plot(time,ref)
hold on
plot(time,sam,'r')

fftref=fft(ref,513);
fftsam=fft(sam,513);
timenew=(time(2)-time(1)).*[0:512];
freq=eps:1/timenew(length(timenew)):(length(timenew)-1)/timenew(length(timenew));
phasere_0=angle(fftref);
phasesam_0=angle(fftsam);
ABS=freq';
phaseref=abs(unwrap(phasere_0));
phasesam=abs(unwrap(phasesam_0));
difphase_0=abs(phaseref-phasesam);
difphase=abs(difphase_0) 

figure 
plot(freq,phaseref)
hold on
plot(freq,phasesam,'r')
plot(freq,difphase,'g')
xlim([0.1e12,2e12])

figure            
plot(freq,abs(fftref))
hold on
plot(freq,abs(fftsam),'r')
xlim([0.1e12,2e12]) 

c=3e8;
L=1e-6;
n=difphase.*c./(2*pi.*freq'.*L)+1;
figure
plot(freq,n)
xlim([0.2e12,2e12])
ylim([1.1,1.5])

t=abs(fftsam)./abs(fftref);
K=-((log(t)*c)./(2*pi.*freq'*L));
figure               
plot(freq,K)
xlim([0,2e12])
ylim([0,600])

b=(4*pi.*freq'.*K)/c ;
figure               
plot(freq,b,'-*')
xlim([0.2e12,2e12])

R=(n.^2)-(K.^2);
figure               
plot(freq,R)
xlim([0.2e12,2e12])
ylim([0,5e4])

R_img=2.*n.*K
figure                
plot(freq,R_img)
xlim([0.2e12,1.6e12])
ylim([0,5e4])



