extending an array for zero padding,

2 views (last 30 days)
Hi, I want to see the effect of zero padding in OCT simulation, I am stuck at getting the last value of K to extend the array, line number (31), K is decreasing. The error says elements on both sides does'nt match
close all
clearvars
%gaussian source
lambda = load('Wavelengths.dat').*10^-9; %source wavelengths in meter
k= (2*pi)./lambda; %wavenumber non-linear
deltalambda=lambda(end)-lambda(1); %bandwidth
lambdacentral=(lambda(end)+lambda(1))/2;%central bandwidth
k0 = 2*pi/lambdacentral;% central wavenumber
deltak= 2*pi*deltalambda/(sqrt(2*log(2))*(lambdacentral)^2);%spectrum
s = (1/deltak*sqrt(pi)).*gaussmf(k, [deltak k0]); %generating gaussian spectrum source
figure (), plot (k, s), axis tight, title ('Light Source Spectrum') ,xlabel ("wavenumber"), ylabel ('Amplitude')
%% Interference spectrum
ro = 0.9;% sensitivity at detector
rref = 0.8;% reflectivity from reference
RR=rref^2; %reflectance from reference
rsample = 0.1;%reflectivity from sample
RS=rsample^2;%reflectance from sample
zr=0.5*10^-3;% reference arm length in meter
zs=zr+200e-06;% sample arm length in meter
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)));%non-linear k-space signal
end
K=linspace(k(1),k(end),2048);
I=interp1(k,I_NL,K);% k contains the sample points and I NL contains the corresponding values and K contains the co ordinates of the query
I(end+1:2^15)=0;
K(end+1:2^15) = K(end):K(2)-K(1):(2^15-2048)*(K(2)-K(1));% what will be the code for the last value
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)));
%figure,plot(1:2048,Aline_NL,'r',1:2048,Aline,'b');
%% Depth
%total number of samples or channels
M=length(I);
krange= K(1,1)-K(1,length(K));%range in k domain
%zz = linspace(0,(pi)./(M.*krange),M/2);
deltask=krange./M;% sampling interval in K domain
depthmax=((M-1).*(pi/krange))*10^6;%max imaging depth
depthsz=pi/M.*deltask; %sampling in z domain
%z=linspace(0,((M-1).*(pi/krange))*10^6,M);%going from 0 to zmax
%figure(), plot(z,Aline), title('FD-OCT: A-scan'), xlabel('Depth (um)'), ylabel('Amplitude (a.u.)');
%% Depth
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.)');

Accepted Answer

Alan Moses
Alan Moses on 13 Aug 2020
Hi, it is my understanding that the array ‘K’ needs to be extended to the same size as that of array ‘L’. You can use the linspace function to do this, as mentioned below. Note the formula used for finding last element.
K(end+1:2^15) = linspace(K(end)+(K(2)-K(1)),(2^15-2048)*(K(2)-K(1))+K(end),2^15-2048);
Hope this helps!

More Answers (0)

Categories

Find more on 3-D Scene Control in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!