⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backlash.m

📁 Conversion from absorbance to transmittance or vice versa 将光从吸光度转为透光度
💻 M
字号:
function [Xcorr,meanbase] = backlash(X)
% function Xcorr = backlash(X);
%
% This function corrects for non-zero and/or n-th order baseline in spectra.  
% The user defines the baseline anchor points, i.e the zero component regions
% and may choose between  mean or spectrum by spectrum baseline calculation.
% The order of the polynom to be used may vary from 0 to bignumber. 
% NB! If only one spectrum is used as input, separate(0) option MUST be used
% e.nodland 150595

[n,m]=size(X);
slutt=1;
meanX=mean(X(:,1:m)')';
hold off
if m==1
	plot(X);

	hold on
else
	plot(X(:,1:m-1:m),'b');
	hold on;
	plot(meanX,'m')
end
v=[1 n min(min(X)) (max(max(X))/3)];
axis(v);
title('The first,last and the mean spectrum. Pick your anchor points!')
disp('Home in on the fist anchor by clicking once')
[x,y]=ginput(1);
u=floor(x);
if u < 1
   u = 1;
end
if u < n/4;
   xsp=1;
   xep=n/2;
elseif u > 3*n/4;
   xsp=n/2;
   xep=n;
else
   xsp=u-n/4;
   xep=u+n/4;
end
v=[xsp xep min(min(X)) (max(max(X))/3)];
axis(v);
frekvenser=[];
regions=0;
while slutt == 1
	regions=regions+1;
	[l,h]=size(frekvenser);
	disp('Use the mouse pointer to mark suspected zero component regions')
	disp('Mark the lower index, in the lowest region, first')
	[x,y]=ginput(2);
	low=floor(x(1));
	if low < 1
		low=1;
	end
	high=ceil(x(2));
	if high > n
		high=n;
	end
	frekvenser(h+1:h+1+high-low)=[low:high];
	ys(h+1:h+1+high-low,:)=X(low:high,1:m);
	f_hold(regions,:)=[low,high];
	if m==1
		plot(low:high,X(low:high),'rx')
	else
		plot(low:high,meanX(low:high),'rx')
   end
   if regions ==1
         axis tight
	end
   slutt=input('More anchor points? (1=Yes, 0=No) ');   
end

hold off
orden=input('Enter the order of the baseline: ');
valg=input('Mean or separate baseline correction ? (1=Mean, 0=Separate) ');
if valg == 1
	mean_ys=mean(ys');
	b=polyfit(frekvenser,mean_ys,orden);	
	baseline=polyval(b,(1:n)');
	Xcorr=X-baseline*ones(1,m);

else
	for i=1:m
		b=polyfit(frekvenser,ys(:,i)',orden);
		%baseline(:,i)=polyval(b,(1:n)');
		baseline=[baseline polyval(b,(1:n)')];
	end
	Xcorr=X-baseline;
%	Xcorr=Xcorr+baseline(1,1);

end

%resultat plotting

if valg == 1
	meanbase=baseline;
else
	meanbase=mean(baseline'); 
end
if m==1
	plot(X), hold on, plot(Xcorr,'m');
	plot(baseline,'r')
else
meanX(:,2)=mean(Xcorr')';
plot(meanX),hold on;
plot(meanbase,'r')
plot(zeros(size(meanX(:,1))),'k')
end
for k=1:regions
	if m==1
		plot(f_hold(k,1):f_hold(k,2),X(f_hold(k,1):f_hold(k,2)),'rx')
	else
 		plot(f_hold(k,1):f_hold(k,2),meanX(f_hold(k,1):f_hold(k,2)),'rx')
	end
end
axis tight
hold off
title('Mean of X(b) & Xcorr(g), base(r) & zero(k)-line, and the anchors(rx)');  
disp([num2str(orden),'. order baseline using ',num2str(regions),' anchors at:'])
disp(f_hold)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -