필터 지우기
필터 지우기

extending an array for zero padding,

조회 수: 2 (최근 30일)
Rimple Poonia Dabas
Rimple Poonia Dabas 2020년 7월 17일
답변: Alan Moses 2020년 8월 13일
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.)');

채택된 답변

Alan Moses
Alan Moses 2020년 8월 13일
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!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Crystals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by