1 /*--------------------------------------------------------------
2 	Signal processing function library    libsgp
3 	  ( Get peaks in sequence  Rev.960229)
4 		Written by H.Goto , May 1994
5 --------------------------------------------------------------*/
6 
7 /*--------------------------------------------------------------------
8   Copyright (C) 1994  Hideaki Goto
9 
10         All Rights Reserved
11 
12   Permission to use, copy, modify, and distribute this software and
13   its documentation for any purpose is hereby granted without fee,
14   provided that (i) the above copyright notice and this permission
15   notice appear in all copies and in supporting documentation, (ii)
16   the name of the author, Hideaki Goto, may not be used in any
17   advertising or otherwise to promote the sale, use or other
18   dealings in this software without prior written authorization
19   from the author, (iii) this software may not be used for
20   commercial products without prior written permission from the
21   author, and (iv) the notice of the modification is specified in
22   case of that the modified copies of this software are distributed.
23 
24   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
25   THE AUTHOR WILL NOT BE RESPONSIBLE FOR ANY DAMAGE CAUSED BY THIS
26   SOFTWARE.
27 --------------------------------------------------------------------*/
28 
29 
30 #include	<stdio.h>
31 
32 #include	"sgplib.h"
33 
34 
35 /*------------------------------------------------------
36 	Get peaks
37 ------------------------------------------------------*/
38 
sgp_getpeaksuc(uchar * src,peaklisti * pks,int size,int listsize,int thlow,int thhigh)39 int sgp_getpeaksuc(uchar *src,peaklisti *pks, \
40 			int size,int listsize,int thlow,int thhigh){
41 	int	ix,l;
42 	int	dx,dx0,x0;
43 	int	count;
44 	count = 0;
45 	l = 0;
46 	x0 = dx0 = 0;
47 	for ( ix=0 ; ix<size ; ++ix ){
48 		dx = (int)((uint)src[ix]) - x0;
49 		if ( dx == 0 ){
50 			if ( dx0 > 0 )  ++l;  else  l = 0;
51 		}
52 		else{	if ( dx < 0 ){
53 				if ( l != 0 ){
54 					if ( (x0 >= thlow) && (x0 <= thhigh) ){
55 						if ( (++count) > listsize )  break;
56 						pks->pos = ix - ((l+1)/2) -1;
57 						pks->value = (int)((uint)x0);
58 						++pks;
59 					}
60 					l = 0;
61 				}
62 				else{	if ( dx0 > 0 ){
63 						if ( (x0 >= thlow) && (x0 <= thhigh) ){
64 							if ( (++count) > listsize )  break;
65 							pks->pos = ix -1;
66 							pks->value = (int)((uint)x0);
67 							++pks;
68 						}
69 					}
70 				}
71 			}
72 			else{	l = 0;
73 			}
74 			dx0 = dx;
75 		}
76 		x0 = (int)((uint)src[ix]);
77 	}
78 	return (count);
79 }
80 
81 
82 
83 
sgp_getpeaksi(int * src,peaklisti * pks,int size,int listsize,int thlow,int thhigh)84 int sgp_getpeaksi(int *src,peaklisti *pks, \
85 			int size,int listsize,int thlow,int thhigh){
86 	int	ix,l;
87 	int	dx,dx0,x0;
88 	int	count;
89 	count = 0;
90 	l = 0;
91 	x0 = dx0 = 0;
92 	for ( ix=0 ; ix<size ; ++ix ){
93 		dx = src[ix] - x0;
94 		if ( dx == 0 ){
95 			if ( dx0 > 0 )  ++l;  else  l = 0;
96 		}
97 		else{	if ( dx < 0 ){
98 				if ( l != 0 ){
99 					if ( (x0 >= thlow) && (x0 <= thhigh) ){
100 						if ( (++count) > listsize )  break;
101 						pks->pos = ix - ((l+1)/2) -1;
102 						pks->value = x0;
103 						++pks;
104 					}
105 					l = 0;
106 				}
107 				else{	if ( dx0 > 0 ){
108 						if ( (x0 >= thlow) && (x0 <= thhigh) ){
109 							if ( (++count) > listsize )  break;
110 							pks->pos = ix -1;
111 							pks->value = x0;
112 							++pks;
113 						}
114 					}
115 				}
116 			}
117 			else{	l = 0;
118 			}
119 			dx0 = dx;
120 		}
121 		x0 = src[ix];
122 	}
123 	return (count);
124 }
125 
126 
127