11'use strict' ;
22
33var fs = require ( 'fs' ) ;
4- var peakPicking = require ( '..' ) ;
4+ const gsd = require ( '..' ) . gsd ;
5+
6+ function lorentzian ( x , x0 = 0 , gamma = 1 ) {
7+ return ( gamma * gamma ) / ( Math . PI * gamma * ( gamma * gamma + ( x - x0 ) * ( x - x0 ) ) ) ;
8+ }
59
610describe ( 'Global spectra deconvolution simple simulated spectrum' , function ( ) {
711
812 // Test case obtained from Pag 443, Chap 8.
913 it ( 'Should provide the right result ...' , function ( ) {
1014 var spectrum = JSON . parse ( fs . readFileSync ( './test//C2.json' , 'utf-8' ) ) ;
11- var result = peakPicking . gsd ( spectrum [ 0 ] , spectrum [ 1 ] , { //noiseLevel: 0.001,
15+ var result = gsd ( spectrum [ 0 ] , spectrum [ 1 ] , { //noiseLevel: 0.001,
1216 minMaxRatio : 0 ,
1317 realTopDetection : true ,
1418 smoothY : false
@@ -23,5 +27,27 @@ describe('Global spectra deconvolution simple simulated spectrum', function () {
2327 //result[1].width.should.approximately(0.006,5e-4);
2428
2529 } ) ;
30+
31+ it ( 'Should give 10 peaks' , function ( ) {
32+ const size = 300 ;
33+ const fourth = size / 11 ;
34+ var times = new Array ( size ) ;
35+ var tic = new Array ( size ) ;
36+ console . log ( "here2" ) ;
37+
38+ for ( var i = 0 ; i < size ; ++ i ) {
39+ times [ i ] = i ;
40+ tic [ i ] = lorentzian ( i , fourth ) + 2 * lorentzian ( i , 2 * fourth ) + lorentzian ( i , 3 * fourth ) + 2 * lorentzian ( i , 4 * fourth ) + lorentzian ( i , 5 * fourth ) + 2 * lorentzian ( i , 6 * fourth ) + lorentzian ( i , 7 * fourth ) + 2 * lorentzian ( i , 8 * fourth ) + lorentzian ( i , 9 * fourth ) + 2 * lorentzian ( i , 10 * fourth ) ;
41+ }
42+ var ans = gsd ( times , tic , {
43+ noiseLevel : 0 ,
44+ realTopDetection : false ,
45+ smoothY : false ,
46+ sgOptions : { windowSize : 5 , polynomial : 3 }
47+ } ) ;
48+
49+ ans . length . should . equal ( 10 ) ;
50+
51+ } ) ;
2652} ) ;
2753
0 commit comments