home *** CD-ROM | disk | FTP | other *** search
/ ftp.disi.unige.it / 2015-02-11.ftp.disi.unige.it.tar / ftp.disi.unige.it / pub / .person / BarlaA / sw / matlab / Cromwell / trivialPeakFinder.m < prev    next >
Text File  |  2007-12-04  |  2KB  |  63 lines

  1. function [Peak, leftMin, rightMin] = trivialPeakFinder(w)
  2. % [PEAKS, LEFTMIN, RIGHTMIN] = mixedup(spectrum)
  3. %
  4. % Input is the intensity levels of a spectrum. We assume the spectrum
  5. % has already been wavelet smoothed and baseline corrected. We identify
  6. % peaks as local maxima.
  7. %
  8. % The return values are:
  9. %    PEAKS: a list of peak locations, in ticks
  10. %    LEFTMIN:    a list of the closest minimum to the left of each peak
  11. %    RIGHTMIN: a list of the closest minimum to the right of each peak
  12.  
  13. % Copyright (c) 2003, 2004 UT M.D. Anderson Cancer Center. All rights reserved.
  14. % See the accompanying file "license.txt" for details.
  15.  
  16. % Original version by Kevin Coombes
  17. % $Revision: 2.2 $
  18. % Last modified by $Author: krc $ on $Date: 2004/03/01 21:41:15 $.
  19.  
  20.  
  21. %% Step 1: Find all local maxima and associated local minima.
  22. x = diff(w);        % first difference
  23. xl = x(1:end-1);    % left side
  24. xr = x(2:end);        % right side
  25. neartop = (xl > 0 & xr <= 0) | (xl == 0 & xr < 0);
  26. nearbot = (xl < 0 & xr >= 0) | (xl == 0 & xr > 0);
  27. xx = 1:length(x);
  28. nb = [1 xx(nearbot)+1];    % tentative minimum
  29. nt = xx(neartop)+1;        % tentative maximum
  30.  
  31. %% Step 2: Coalesce rising plateaus to find the right-most one.
  32. curt = 1;
  33. curb = 1;
  34. Peak = [0];
  35. bots = [1];
  36. numtop = 1;
  37. numbot = 1;
  38. while curt < length(nt) & curb < length(nb),
  39.     while nb(curb)<nt(curt) & curb < length(nb),
  40.        curb = curb+1;
  41.     end
  42.     bots(numbot) = nb(curb);
  43.     numbot = numbot+1;
  44.     while nt(curt) < nb(curb) & curt < length(nt),
  45.        curt = curt + 1;
  46.     end
  47.     Peak(numtop) = nt(curt);
  48.    numtop = numtop + 1;
  49. end
  50. clear numtop numbot curt curb nb nt nearbot neartop
  51.  
  52. % After combining maxima, we then figure out where the closest minima
  53. % are to both left and right. These might not agree for adjacent peaks
  54. % because of the presence of plateaus.
  55. leftMin = [1];    % list of resolvable minima to left of peak.
  56. rightMin = [1];    % similar list to right of peak.
  57. for i = 2:length(Peak),
  58.    temp = Peak(i-1):Peak(i);
  59.    leftMin(i) = max(temp(w(temp)==min(w(temp))));
  60.    rightMin(i) = min(temp(w(temp)==min(w(temp))));
  61. end
  62. rightMin = [rightMin(2:end) length(x)];
  63.