close all
clearvars
lambda = load('Wavelengths.dat').*10^-9;
k= (2*pi)./lambda;
deltalambda=lambda(end)-lambda(1);
lambdacentral=(lambda(end)+lambda(1))/2;
k0 = 2*pi/lambdacentral;
deltak= 2*pi*deltalambda/(sqrt(2*log(2))*(lambdacentral)^2);
s = (1/deltak*sqrt(pi)).*gaussmf(k, [deltak k0]);
figure (), plot (k, s), axis tight, title ('Light Source Spectrum') ,xlabel ("wavenumber"), ylabel ('Amplitude')
ro = 0.9;
rref = 0.8;
RR=rref^2;
rsample = 0.1;
RS=rsample^2;
zr=0.5*10^-3;
zs=zr+200e-06;
for i=1:length(k)
I_NL(i)=(ro/4).*((s(i).*(RR+RS)))+(ro/2).*(s(i).*sqrt(RR*RS).*cos(2.*k(i).*(zr-zs)));
end
K=linspace(k(1),k(end),2048);
I=interp1(k,I_NL,K);
I(end+1:2^15)=0;
K(end+1:2^15) = K(end):K(2)-K(1):(2^15-2048)*(K(2)-K(1));
figure,plot(k,I_NL,'-o',K,I,'-s'),title ('Spectrum'), xlabel('wave number'), ylabel('I(k)');
Aline_NL=abs((ifft(I_NL)));
Aline=abs((ifft(I)));
M=length(I);
krange= K(1,1)-K(1,length(K));
deltask=krange./M;
depthmax=((M-1).*(pi/krange))*10^6;
depthsz=pi/M.*deltask;
z=[0:length(M)-1].*(pi/(max(K)-min(K)))*1000;
figure(), plot(z,abs(ifft(I)),'r',z,abs(ifft(I_NL)),'b'), title('FD-OCT: A-scan'), xlabel('Depth (mm)'), ylabel('Amplitude (a.u.)');