function [MZ,Y] = msbatchprocessing(filename)
% MSBATCHPROCESSING Demonstration function for BIODISTCOMPDEMO
%
% [MZ,Y] = MSBATCHPROCESSING(FILENAME) Preprocesses the spectrogram in file
% FILENAME and returns the mass/charge (MZ) and ion intensities (Y) vectors. 
%
% Hard-coded parameters in the preprocessing steps have been adjusted to
% deal with the high-resolution spectrograms of the demonstration.

% read the two-column text file with mass-charge and intensity values
D = textread(filename);

% resample the signal to 15000 points between 710 and 11900
[MZ,YR]=msresample(D(:,1),D(:,2),15000,'RANGE',[710,11900]);

% align the spectrograms to two good reference peaks
P = [3883.766 7766.166];
YA = msalign(MZ,YR,P,'WIDTH',2);

% estimate and adjust the background
YB = msbackadj(MZ,YA,'STEP',50,'WINDOW',50);

% reduce the noise using a nonparametric filter
Y = mslowess(MZ,YB,'SPAN',5);
