%ShowPeakName
%
%This function will add labels, containing the peak positions of the bands,
%on a plot. The function looks for bands based on the first and second
%derivative. Peak positions are calculated based on fourier interpolation.
%
%Syntax:
% peak = ShowPeakName (treshhold, ExtendedInfo, sigdigit)
%
%With:
% treshhold: a treshhold value for the second derivative, peaks with a
% higher value for the second derivative will be named, e.g. 1e-4 for
% a normalized spectrum
% ExtendedInfo: optional: boolean: if true, x-axis position, x-axis
% position of the nearest pixel and paek intensity are given in the figure
% sigdigit: optional: the number of digits after the comma.
% peak: a cellstring array, containing the peak positions, useful for
% generating tables or databases with peak positions
%
%See also: GetPeakPos, Savgol.
%
%Examples:
% ShowPeakName (1e-4) % show the peak frequencies on the figure
% peaks = ShowPeakName (1e-4) % obtain a list of peak frequencies
% ShowPeakName (1e-4, 1) % also show the nearest pixel number and peak intensity in the figure
% ShowPeakName (1e-4, 0, 0) % round the peak frequencies to the nearest integer
%This software package is dual licensed. You can use it according to the terms
%of either the GPLv3 or the BSD license.
%
%The ShowPeaks toolbox for MATLAB: routines for peaks detection
%C 2004-2008, Kris De Gussem, Raman Spectroscopy Research Group, Department
%of analytical chemistry, Ghent University
%C 2009 Kris De Gussem
%
%This file is part of ShowPeaks. ShowPeaks is used a.o. by the Biodata toolb ox.
%
%ShowPeaks is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.
%
%ShowPeaks is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with ShowPeaks. If not, see <http://www.gnu.org/licenses/>.
%Copyright (c) 2004-2009, Kris De Gussem
%All rights reserved.
%
%Redistribution and use in source and binary forms, with or without
%modification, are permitted provided that the following conditions are
%met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
% * Neither the name of Raman Spectroscopy Research Group, Department of
% analytical chemistry, Ghent University nor the names
% of its contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
%THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
%AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
%IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
%ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
%LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
%CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
%SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
%INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
%ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
%POSSIBILITY OF SUCH DAMAGE.
function peak = ShowPeakName (treshhold, ExtendedInfo, sigdigit)
switch nargin
case 1
ExtendedInfo = false;
sigdigit = 1;
case 2
sigdigit = 1;
case 3
otherwise
error ('Calibration:msg', 'Give a secord derivative threshold value for peak detection ...');
end
if treshhold <= 0
error ('Calibration:msg', 'Threshold value should be a positive value...');
end
fig=get(0,'CurrentFigure');
data=findobj(get(fig,'Children'),'type','line');
xdata=get(data,'xdata');
ydata=get(data,'ydata') ;
if iscell (xdata)
xdata=xdata{length (xdata)};
end
if iscell (ydata)
ydata=ydata{length (ydata)};
end
if xor(iscell(ydata),iscell(xdata)) %if only one of xdata/ydata a cell: something wrong, return
return
elseif iscell(xdata) % if xdata is a cell: multiple plot
xaxis=xdata{1};
yaxis=ydata{1};
else % else single plot
xaxis=xdata;
yaxis=ydata;
end
pos = GetPeakPos (yaxis, xaxis, treshhold);
%wat volgt = aanduiden piek
le = length (pos);
if ExtendedInfo
peak = zeros(le,4);
else
peak = cell(le,1);
end
for i = 1:le
pos_peak = PeakPosFFT (yaxis, xaxis, pos(i));
xpeak = xaxis(pos(i));
ypeak = yaxis(pos(i));
commanotation = ['.' num2str(sigdigit) 'f'];
if ExtendedInfo
intensity = interp1 (xaxis, yaxis, pos_peak, 'linear');
peaktext = [num2str(pos_peak, ['%11' commanotation]) ' (' num2str(xaxis(pos(i)),['%11' commanotation]) '): ' num2str(intensity, ['%' commanotation]) ' counts'];
peak(i,1) = pos_peak;
peak(i,2) = xaxis(pos(i));
peak(i,3) = intensity;
peak(i,4) = pos(i);
else
peaktext = num2str(pos_peak, ['%11' commanotation]);
peak{i} = peaktext;
end
text(xpeak,ypeak,peaktext,'rotation',90); % een tekstje met waarde positie
end