@@ -4734,7 +4734,7 @@ return /******/ (function(modules) { // webpackBootstrap
47344734 var SG = __webpack_require__ ( 20 ) ;
47354735
47364736 var sgDefOptions = {
4737- windowSize : 5 ,
4737+ windowSize : 9 ,
47384738 polynomial : 3
47394739 } ;
47404740
@@ -4744,56 +4744,70 @@ return /******/ (function(modules) { // webpackBootstrap
47444744 var options = Object . create ( options || { } ) ;
47454745 if ( options . minMaxRatio === undefined ) options . minMaxRatio = 0.00025 ;
47464746 if ( options . broadRatio === undefined ) options . broadRatio = 0.00 ;
4747- if ( options . noiseLevel === undefined ) options . noiseLevel = 0 ;
4747+ if ( options . noiseLevel === undefined ) options . noiseLevel = undefined ;
4748+ if ( options . noiseFactor === undefined ) options . noiseFactor = 3 ;
47484749 if ( options . maxCriteria === undefined ) options . maxCriteria = true ;
47494750 if ( options . smoothY === undefined ) options . smoothY = true ;
47504751 if ( options . realTopDetection === undefined ) options . realTopDetection = false ;
47514752
47524753 var sgOptions = extend ( { } , sgDefOptions , options . sgOptions ) ;
47534754
4754- //Transform y to use the standard algorithm.
4755- var yCorrection = { m :1 , b :0 } ;
4756- if ( ! options . maxCriteria || options . noiseLevel > 0 ) {
4757- y = [ ] . concat ( y ) ;
4758- if ( ! options . maxCriteria ) {
4759- yCorrection = { m :- 1 , b :stats . array . max ( y ) } ;
4760- for ( var i = 0 ; i < y . length ; i ++ ) {
4761- y [ i ] = - y [ i ] + yCorrection . b ;
4762- }
4763- options . noiseLevel = - options . noiseLevel + yCorrection . b ;
4764- }
4765- if ( options . noiseLevel > 0 ) {
4766- for ( var i = 0 ; i < y . length ; i ++ ) {
4767- if ( Math . abs ( y [ i ] ) < options . noiseLevel ) {
4768- y [ i ] = 0 ;
4769- }
4755+ //console.log(JSON.stringify(stats.array.minMax(y)));
4756+ if ( options . noiseLevel === undefined ) {
4757+ //We have to know if x is equally spaced
4758+ var maxDx = 0 , minDx = Number . MAX_VALUE , tmp ;
4759+ for ( var i = 0 ; i < x . length - 1 ; i ++ ) {
4760+ var tmp = Math . abs ( x [ i + 1 ] - x [ i ] ) ;
4761+ if ( tmp < minDx ) {
4762+ minDx = tmp ;
4763+ }
4764+ if ( tmp > maxDx ) {
4765+ maxDx = tmp ;
47704766 }
47714767 }
4772- }
47734768
4774- //We have to know if x is equally spaced
4775- var maxDx = 0 , minDx = Number . MAX_VALUE , tmp ;
4776- for ( var i = 0 ; i < x . length - 1 ; i ++ ) {
4777- var tmp = Math . abs ( x [ i + 1 ] - x [ i ] ) ;
4778- if ( tmp < minDx ) {
4779- minDx = tmp ;
4769+ if ( ( maxDx - minDx ) / maxDx < 0.05 ) {
4770+
4771+ options . noiseLevel = getNoiseLevel ( y ) ;
4772+ //console.log(options.noiseLevel+" "+stats.array.median(y));
47804773 }
4781- if ( tmp > maxDx ) {
4782- maxDx = tmp ;
4774+ else {
4775+ options . noiseLevel = 0 ;
4776+ }
4777+ }
4778+ //console.log("options.noiseLevel "+options.noiseLevel);
4779+ y = [ ] . concat ( y ) ;
4780+ var yCorrection = { m :1 , b :options . noiseLevel } ;
4781+ if ( ! options . maxCriteria ) {
4782+ yCorrection . m = - 1 ;
4783+ yCorrection . b *= - 1 ;
4784+ }
4785+
4786+ for ( var i = 0 ; i < y . length ; i ++ ) {
4787+ y [ i ] = yCorrection . m * y [ i ] - yCorrection . b ;
4788+ }
4789+
4790+ for ( var i = 0 ; i < y . length ; i ++ ) {
4791+ if ( y [ i ] < 0 ) {
4792+ y [ i ] = 0 ;
47834793 }
47844794 }
4795+
47854796 //If the max difference between delta x is less than 5%, then, we can assume it to be equally spaced variable
4797+ var Y = y ;
47864798 if ( ( maxDx - minDx ) / maxDx < 0.05 ) {
4787- var Y = SG ( y , x [ 1 ] - x [ 0 ] , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :0 } ) ;
4799+ if ( options . smoothY )
4800+ Y = SG ( y , x [ 1 ] - x [ 0 ] , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :0 } ) ;
47884801 var dY = SG ( y , x [ 1 ] - x [ 0 ] , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :1 } ) ;
47894802 var ddY = SG ( y , x [ 1 ] - x [ 0 ] , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :2 } ) ;
47904803 }
47914804 else {
4792- var Y = SG ( y , x , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :0 } ) ;
4805+ if ( options . smoothY )
4806+ Y = SG ( y , x , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :0 } ) ;
47934807 var dY = SG ( y , x , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :1 } ) ;
47944808 var ddY = SG ( y , x , { windowSize :sgOptions . windowSize , polynomial :sgOptions . polynomial , derivative :2 } ) ;
47954809 }
4796-
4810+
47974811 var X = x ;
47984812 var dx = x [ 1 ] - x [ 0 ] ;
47994813 var maxDdy = 0 ;
@@ -4849,9 +4863,6 @@ return /******/ (function(modules) { // webpackBootstrap
48494863 }
48504864 }
48514865 }
4852- if ( options . realTopDetection ) {
4853- realTopDetection ( minddY , X , Y ) ;
4854- }
48554866 //
48564867 //console.log(intervalL.length+" "+minddY.length+" "+broadMask.length);
48574868 var signals = [ ] ;
@@ -4883,6 +4894,7 @@ return /******/ (function(modules) { // webpackBootstrap
48834894 //console.log(height);
48844895 if ( Math . abs ( Y [ minddY [ j ] ] ) > options . minMaxRatio * maxY ) {
48854896 signals . push ( {
4897+ i :minddY [ j ] ,
48864898 x : frequency ,
48874899 y : ( Y [ minddY [ j ] ] - yCorrection . b ) / yCorrection . m ,
48884900 width :Math . abs ( intervalR [ possible ] - intervalL [ possible ] ) , //widthCorrection
@@ -4892,6 +4904,16 @@ return /******/ (function(modules) { // webpackBootstrap
48924904 }
48934905 }
48944906
4907+
4908+ if ( options . realTopDetection ) {
4909+ realTopDetection ( signals , X , Y ) ;
4910+ }
4911+
4912+ //Correct the values to fit the original spectra data
4913+ for ( var j = 0 ; j < signals . length ; j ++ ) {
4914+ signals [ j ] . base = options . noiseLevel ;
4915+ }
4916+
48954917 signals . sort ( function ( a , b ) {
48964918 return a . x - b . x ;
48974919 } ) ;
@@ -4900,11 +4922,35 @@ return /******/ (function(modules) { // webpackBootstrap
49004922
49014923 }
49024924
4925+ function getNoiseLevel ( y ) {
4926+ var mean = 0 , stddev = 0 ;
4927+ var length = y . length , i = 0 ;
4928+ for ( i = 0 ; i < length ; i ++ ) {
4929+ mean += y [ i ] ;
4930+ }
4931+ mean /= length ;
4932+ var averageDeviations = new Array ( length ) ;
4933+ for ( i = 0 ; i < length ; i ++ )
4934+ averageDeviations [ i ] = Math . abs ( y [ i ] - mean ) ;
4935+ averageDeviations . sort ( ) ;
4936+ if ( length % 2 == 1 ) {
4937+ stddev = averageDeviations [ ( length - 1 ) / 2 ] / 0.6745 ;
4938+ } else {
4939+ stddev = 0.5 * ( averageDeviations [ length / 2 ] + averageDeviations [ length / 2 - 1 ] ) / 0.6745 ;
4940+ }
4941+
4942+ return stddev ;
4943+ }
4944+
49034945 function realTopDetection ( peakList , x , y ) {
4946+ //console.log(peakList);
4947+ //console.log(x);
4948+ //console.log(y);
49044949 var listP = [ ] ;
49054950 var alpha , beta , gamma , p , currentPoint ;
49064951 for ( var j = 0 ; j < peakList . length ; j ++ ) {
4907- currentPoint = peakList [ j ] ; //peakList[j][2];
4952+ currentPoint = peakList [ j ] . i ; //peakList[j][2];
4953+ var tmp = currentPoint ;
49084954 //The detected peak could be moved 1 or 2 unit to left or right.
49094955 if ( y [ currentPoint - 1 ] >= y [ currentPoint - 2 ]
49104956 && y [ currentPoint - 1 ] >= y [ currentPoint ] ) {
@@ -4935,10 +4981,12 @@ return /******/ (function(modules) { // webpackBootstrap
49354981 beta = 20 * Math . log10 ( y [ currentPoint ] ) ;
49364982 gamma = 20 * Math . log10 ( y [ currentPoint + 1 ] ) ;
49374983 p = 0.5 * ( alpha - gamma ) / ( alpha - 2 * beta + gamma ) ;
4938-
4939- x [ peakList [ j ] ] = x [ currentPoint ] + ( x [ currentPoint ] - x [ currentPoint - 1 ] ) * p ;
4940- y [ peakList [ j ] ] = y [ currentPoint ] - 0.25 * ( y [ currentPoint - 1 ]
4941- - [ currentPoint + 1 ] ) * p ; //signal.peaks[j].intensity);
4984+ //console.log("p: "+p);
4985+ //console.log(x[currentPoint]+" "+tmp+" "+currentPoint);
4986+ peakList [ j ] . x = x [ currentPoint ] + ( x [ currentPoint ] - x [ currentPoint - 1 ] ) * p ;
4987+ peakList [ j ] . y = y [ currentPoint ] - 0.25 * ( y [ currentPoint - 1 ]
4988+ - y [ currentPoint + 1 ] ) * p ; //signal.peaks[j].intensity);
4989+ //console.log(y[tmp]+" "+peakList[j].y);
49424990 }
49434991 }
49444992 }
@@ -6042,9 +6090,9 @@ return /******/ (function(modules) { // webpackBootstrap
60426090 var stat = __webpack_require__ ( 16 ) ;
60436091
60446092 var defaultOptions = {
6045- windowSize : 11 ,
6093+ windowSize : 9 ,
60466094 derivative : 0 ,
6047- polynomial : 2 ,
6095+ polynomial : 3 ,
60486096 } ;
60496097
60506098
0 commit comments