Code covered by the BSD License  

Highlights from
TOFsPRO toolbox

from TOFsPRO toolbox by Dariya Malyarenko
Signal processing for time-of-flight mass spectra over the broad m/z range (1-200 kDa)

findBsEnv(sgl, rstp)
function [tenv, senv] = findBsEnv(sgl, rstp) 

%%----------------------------------------------------
%% Find time samples for noise (to fit baseline envelope) in early TOF signal
%%
%% INPUT:
%% sgl - observed unprocessed discrete TOF signal
%% rstp - constant resampling step (odd; above 100; 199 is default)
%%
%% OUTPUT:
%% tenv - TOF coordinates of the envelope
%% senv - signal of the envelope
%%
%% NOTES:
%% --1-- Created by DM (dimaly@wm.edu) 10/31/07
%% --2-- No self-optimization code is included yet, but defaults work
%
% USAGE:
% [tenv, senv] = findBsEnv(sgl, rstp);
% Dependency: none
%

t1=1:length(sgl); t1=t1';

% rstp = 199; %default

trs=1:rstp:length(t1);
k=1;sigr_stp=zeros(length(trs),1);
ks=(rstp-1)/2;
sigr_stp(1)=sum(sgl(1:ks));
sigr_stp(end)=sum(sgl(trs(end)-ks:trs(end))); 
for jk=trs(2):rstp:trs(end-1)
    k=k+1; 
    sigr_stp(k)= sum(sgl(jk-ks:jk+ks));
end;

x = diff(sigr_stp);		% first difference
xl = x(1:end-1);	% left side
xr = x(2:end);		% right side

nearbot = (xl < 0 & xr >= 0) | (xl == 0 & xr > 0);
xx = 1:length(x);
nb = [1 xx(nearbot)+1];	% tentative minimum
%length(nb)
[smax, imax]=max(sigr_stp(nb));

ts=nb(imax);
nxt=imax+1;

while nxt<=length(nb) & sigr_stp(nb(nxt))>0.01*sigr_stp(nb(imax)) & sigr_stp(nb(nxt))> 1
if sigr_stp(nb(nxt))< sigr_stp(ts(end)) ts=[ts,nb(nxt)]; end;
nxt=nxt+1;
end;
ts=ts';
tenv=trs(ts);
senv=sigr_stp(ts)/rstp;
%plot(1:length(sgl), sgl, tenv, senv)
return;

Contact us at files@mathworks.com