1 Introduction

Obesity is defined as the accumulation of excess body fat deposition in relation to height and sex [1]. The prevalence of obesity has been steadily increasing throughout the last decades owing to an increase in economic growth, industrialization, the adoption of a sedentary lifestyle, and the increased consumption of processed foods. It affects around a third of the current world population. It is estimated that by 2030, 38% and 20% of the worldwide population will be overweight and obese, respectively [2]. Obesity increases risk factors of a variety of chronic diseases such as cardiovascular, immunological, and neurological diseases and is a major risk factor of developing type 2 diabetes (T2D).

While there are various interventions for obesity and diabetes such as behavioral modifications, diets, and medications, it has been shown that there is a tendency for patients to regain weight after a certain time since the body can build tolerance to medications rendering them ineffective [3]. In addition, medications may cause potential harmful side effects such as kidney failure [4].

Bariatric surgery has been increasingly used to treat obesity and diabetes. In one meta-analysis study consisting of 3188 patients who underwent bariatric surgery, obesity was resolved in 78% of patients and resolved or improved in 87% of patients [5]. There are various physiological and anatomical mechanisms that explain why bariatric surgery is effective in treating diabetes and obesity: a reduction in food intake due to reduction in stomach size, reduced intestinal absorption due to intestinal bypass, inhibition of a hunger hormone, ghrelin due to resection of the majority part of the stomach where ghrelin is secreted, increased release of glucagon-like peptide-1 (GLP-1). Suppression of ghrelin and enhancement of GLP-1 is known to stimulate insulin secretion, leading to a reduction in blood glucose [6]. While the bariatric surgery is effective in most cases, it is irreversible in most cases, invasive, expensive, and may have complications such as infection or bleeding [7].

The basic rhythmic event of myoelectrical activity of the intestines is called slow wave and characterized by a quasi-periodical signal of varying frequencies: 0.15–0.20 Hz and 0.58–0.82 Hz for humans and rats, respectively [89]. The intestinal slow wave determines the frequency of intestinal contractions and the propagation of intestinal peristalsis along the small intestine. When the slow waves are superimposed with spikes, the small intestine contracts.

Intestinal electrical stimulation (IES) was introduced for treating intestinal dysmotility and obesity [10]. Typically, IES is delivered at a frequency similar to the intrinsic frequency of small intestinal slow waves and designed to accelerate intestinal transit but delay gastric emptying (Fig. 1). The IES-induced delay in gastric emptying results in reduced food intake and decreased ghrelin release, whereas the IES-induced acceleration in small intestinal transit reduces nutrient absorption and enhanced release of glucagon-like peptide-1 (GLP-1) [11,12,13,14]. These combined effects lead to weight loss and reduced blood glucose. Accordingly, IES has a great potential for treating obesity and diabetes [8, 13, 15]. Due to its similarity in mechanisms of action with the gastric bypass procedure, IES is also called electronic bypass.

Fig. 1
figure 1

Mechanisms of intestinal electrical stimulation for treating obesity and diabetes

Subsequent research has demonstrated that IES delivered in synchronization with small intestinal slow waves, a method called synchronized IES or SIES is more potent than IES in accelerating small intestinal transit [16]. For the implementation of SIES, accurate and real-time detection of slow wave peaks is required. Since IES is accomplished via a surgically implanted pulse generator [17], it is critically important that the peak detection algorithm must be as efficient as possible, i.e., use less computational power to prolong the limited battery life imbedded in the pulse generator.

There are a variety of methods to detect peaks. Those include the traditional window threshold technique [1718], the usage of multiple transform functions such as wavelet and Hilbert transforms [1920], hidden Markov models, clustering techniques [21], and artificial neural networks [2223]. Despite the abundance of algorithms, most of them typically involve extensive pre-processing and feature extraction and thus are computationally expensive. In addition, some of them require the presence of an entire signal and thus are suitable only for an offline estimation. Detecting peaks in signals is a significant step in most biomedical applications. So far, several different approaches have been used to detect peaks in biomedical signals, such as artificial neural networks (ANN), morphological filtering, Kalman filtering (KF), Gaussian derivative filtering, and nonlinear energy operators (NEO) [24,25,26,27,28,29,30].

The problem with most current peak detection methods is that they are usually related to the free parameters in the algorithm such as window lengths or thresholds that allow those methods to detect peak values. However, algorithms with some common features are excluded from the detection of R peaks in electroencephalogram (ECG) signals or the use of special parameters such as peaks in chromatographic recordings. In addition, the presence of noise in the recorded signal is a challenge for current peak detection methods [28, 31,32,33,34,35].

Detection of peaks in intestinal slow waves (ISW) in rats is important for both qualitative and quantitative analyses. This is because the amount of information increases as more peaks are identified. However, peak overlap and baseline noise make peak detection relatively difficult. Peak location and amplitude are best estimated when the exact peak shape model and peak width are known in advance. In addition, a false peak may be detected when the signal-to-noise ratio is low or there are artifacts with high amplitude, or a peak may be missed when the occurrence of overlap is not recognized. The most commonly used detection methods do not use peak geometry or baseline noise assumptions. Derivatives of the signal are usually evaluated and peaks are detected when the threshold is exceeded. All the information used in these peak detection methods is that the peaks are the rising and falling signals.

Based on the knowledge that information in ISW datasets can be affected due to shortcomings associated with current peak detection techniques, new simple and useful peak detection algorithms for clinical use with finely modified indexes have been developed [36,37,38,39,40]. We can identify peaks of any signals by (i) finding all local features using the multiscale method and (ii) automatically analyzing the results of the multiscale method used. Specifically, the aim of this study is to develop an online peak detection method that does not contain any free parameters unrelated to ISW and can detect intestinal slow wave peaks with high detection accuracy and minimal delay. In addition, the algorithm needs to be computationally cheap and run-on low memory capacity to enable its integration on a chip implant.

This paper is constructed as follows: section II presents the method of peak detection for SIES. The results of developed peak detection method are shown in section III. Section IV shows an application of the proposed SIES method for lowering blood glucose level in a rodent model of acute hyperglycemia. Discussion is presented in section V. Finally, section VI concludes the paper.

2 Materials and methods

This section describes the proposed algorithm for automatic online detection of peaks in ISW, and how to apply the proposed algorithm to an ISW dataset obtained from rats of varying recording lengths (30–60 min). The closed loop synchronized system hardware has two components. The first component is a recording device that can record slow waves and the second hardware is the stimulator with a peak detection algorithm integrated into it (Fig. 2).

Fig. 2
figure 2

Illustration of the hardware/algorithm of SIES system

The recording device used in the study consists of 4 slow wave recording channels. First, the slow wave signal is collected and converted into digital signal by an A/D converter. The digital signal is passed to a real time peak detection module. Once a peak is detected, it will send out a signal to the stimulator that delivers stimulation to the rat.

2.1 Measurement of the slow wave signal from rats

The small intestinal slow wave was recorded with a bandpass filter (0.05–35 Hz) and sampled at 200 Hz. The filters have a high degree of phase linearity to keep the distortion level as minimal as possible. The slow wave recording includes a fasting session of 30 ~ 60 min after an overnight fasting and a postprandial session of 30 min right after the consumption of 4 g regular chow food. The recordings were obtained from 10 rats. We used two different group of datasets: slow waves in one group for algorithm development and those in another group for validation. For the slow wave peak detection, the data was down sampled to 20 Hz (low pass filter before down-sampling to avoid aliasing) since the frequency of the small intestinal slow waves in rats is lower than 1 Hz.

2.2 Online peak detection algorithm

The proposed technique for peak detection is essentially based on identifying the highest value of the slow waves by comparing each datapoint to succeeding and preceding datapoints.

First, an automatic multiscale-based peak detection (AMPD) algorithm was used on the slow wave recordings to extract the ground truth peaks in offline mode [24]. The AMPD is a peak detection algorithm that is robust in finding peaks of periodic and quasi-periodic noisy signals, thus, making it suitable for the detection of peaks in slow waves. A major advantage of this algorithm is that it is parameter free estimation not requiring any parameters prior to the peak estimation. The algorithm uses a multi-scale technique to find the peaks and outputs a parameter termed the “optimal scale,” λ, which defines the optimal scale for peak estimation of a given quasi-periodic signal. More specifically, a datapoint is defined as a peak if it is bigger than all the values that preceded and succeed it by λ/2 datapoints as follows:

$$x\left(t\right)=\left\{\begin{array}{cc}peak:& x\left(t\right)=max\left\{x\left(k\right):k\in \left[t-\lambda /2,t+\lambda /2\right]\right\}\\ not\;peak:& otherwise\end{array}\right\}$$
(1)

where, x is the slow wave signal and x(t) is the datapoint that’s being evaluated as a peak or not. Clearly, this function requires the a priori availability of the complete signal and is offline in nature.

Next, the formulation for the online peak detection is established. It follows a similar formulation to AMPD (Eq. 1) with a modification for the right-hand estimation. It is clear here that the estimation of a peak can be easily derived by mere left- and right-hand side comparison which corresponds to comparing previous and succeeding datapoints, respectively. Concerning real-time peak detection algorithm, only the left-hand side comparison can be estimated with λ/2 datapoints. This would be problematic for the right-hand side in case λ/2 was substantially large enough since it would introduce a delay between the onset of the peak and the time of estimation. Thus, we introduce an experimental parameter called the “lag,” β, which essentially defines the number of datapoints for right hand estimation. Thus, the formulation for slow wave online peak estimation is defined as follows:

$$x\left(t\right)=\left\{\begin{array}{cc}peak:& x\left(t\right)=max\left\{x\left(k\right):k\in \left[t-\lambda /2,t+\beta \right]\right\}\\ not\; peak:& otherwise\end{array}\right\}$$
(2)

where β ≤ λ/2. This parameter introduces an inherent trade-off between the overall accuracy of the peak detection algorithm and the intestinal stimulation delay. More specifically, for each new element x(t), we are evaluating whether it is larger than all its preceding elements up to λ/2 and all its succeeding elements up to β. Only when those two conditions are met, the candidate peak is labeled as a real peak.

This question explores the presented algorithms for detecting maximum peaks in ISW data in MATLAB format as follows:

\(P\)= [1 1 1.1 1 0.9 1 1 1.1 1 0.9 1 1.1 1 1 0.9 1 1 1.1 1 1 1 1 1.1 0.9 1 1.1 1 1 0.9, …

1 1.1 1 1 1.1 1 0.8 0.9 1 1.2 0.9 1 1 1.1 1.2 1 1.5 1 3 2 5 3 2 1 1 1 0.9 1 1, …

2.6 4 3 3.2 2 1 1 0.8 4 4 2 2.5 1 1 1].

Now that the formulation for the peak estimation is established, additional constraints need to be imposed to avoid early detection of peaks with respect to the last peak. A set of given parameters are defined for establishing the constraints: the average cycle (cycleavg), upper cycle range (cycleupper), and lower cycle range (cyclelower). The average cycle is the average rate of the intestinal slow wave for a given animal. For instance, the slow wave frequencies of a rat are given by the range 0.58–0.82 Hz; thus, the average slow wave cycle range is 1.21–1.72 s which corresponds to an average cycle of 1.46 s. The upper and lower range are defined as 75% and 125% of the average cycle, respectively. Table 1 below summarized all those values for the slow waves of the rats:

Table 1 Summary of frequency ranges, average cycle, upper cycle range, and lower cycle range for the intestinal slow waves in rats

\({\mathrm{Cycle}}_{\mathrm{upper}}\) and \({\mathrm{Cycle}}_{\mathrm{lower}}\) are used to establish a detection window: at the beginning of the slow recording or after estimating a peak, the algorithm will only start to estimate the next peak at defined in the range [\({\mathrm{Cycle}}_{\mathrm{upper}}\) and \({\mathrm{Cycle}}_{\mathrm{lower}}\)] from the last detect peaks.

This detection windows play an important role in avoiding the early detection of peaks with respect to the last peaks to avoid over stimulating the intestines. On the other hand, if no peak is detected in the detection window, then a new relaxed detection window with an upper range of \({\mathrm{Cycle}}_{\mathrm{lower}}\) is initialized from the end range of the previous detection window. This enables the detection of potential missed peaks from a close vicinity instead of initializing a new regular detection window. The block diagram of the online peak detection algorithm is illustrated in Fig. 3. Upon the detection of an intestinal slow wave peak, the following stimulus is delivered: a pulse train with on-time of 0.3 s and off-time of 1.2 s, and pulse frequency of 40 Hz, width of 3 ms, and amplitude of 2 mA [8]. This set of stimulation parameters was previously reported to be able to capture intestinal slow waves [10, 12]. In its applications for treating obesity and diabetes, SIES is typically performed for 1–3 h immediately after food intake [9,10,11].

Fig. 3
figure 3

Flow chart of the online peak detection algorithm

In terms of computational implementation, the algorithm itself was implemented in C code with GNU GCC compiler with code-blocks as IDE. Experiments were run on a computer with an Intel(R)Core (TM) i5-8265U processor running at 1.60 GHz with 8.00 GB of RAM, running C. A 1-dimensional float array buffer was created for storing the values needed for the peak estimation algorithm.

In our work, float values were used, and additional dynamical allocations were required instead of a circular buffer for following reasons: float values use a ring buffer which is an efficient FIFO buffer because it uses a fixed-size array that can be pre-allocated upfront and allows an efficient memory access pattern. In addition, the buffer operations are constant time (0/1), including consuming an element, as it does not require a shifting of elements.

The length of the array is equal to the number of datapoints needed to store the current datapoint to be estimated, x(t) and the values for the left-hand side (λ/2) and right-hand side comparison (β). This array is updated on each iteration when a new value is introduced. In terms of the computational complexity, the algorithm consisted of simple comparative operations (Eq. 2) for the estimation of the peak. Since the general detection of peaks require the observation of a decreasing signal following the peak, the accuracy metric of the peak detection method was estimated as the number of correctly detected peaks that are located at distance ≤ 10% of the cycleavg from the ground truth peaks (derived from AMPD). This corresponds to 146 ms for the rats. White noise was added to the signal to quantify the accuracy of the online peak detection estimation at different SNR levels. A real-time scenario was stimulated by introducing one new input at a time on the offline datasets.

2.3 Adaptive online peak detection algorithm

Another slight modification of the online peak detection algorithm is formulated. The adaptive version of the algorithm aims to regulate the pace of the intestines in case the slow waves are undergoing a dysrhythmic pace (frequency of oscillation is above or below the expected range for an animal). The initial non adaptive algorithm assumes that the intestinal rhythm is oscillating at a normal rate. For the adaptive version, additional mechanism needs to be implemented to regulate back the rhythm to its normal pace. A simple modification is introduced to the original algorithm when the end of the detection window is reached, but no peak is detected. Figure 4 illustrates the potential outcomes for the adaptive online peak detection algorithm for four different scenarios. For dysrhythmia, the detection window might miss a lot of the peak if the fluctuation frequency is too high (peak precedes the detection window) or too low (peak succeeds the detection window). For the former case, it is enough to abstain from sending a stimulation when a peak appears too early wait until a peak appears in the range of the detection window (this is already implemented is the normal online peak detection algorithm). In the latter case, the stimulus is delivered when the end of the detection window is reached so that stimulation frequency is in accordance with the normal frequency range of the intestinal slow waves.

Fig. 4
figure 4

a One-minute slow waves with superimposed spikes. b Illustration of the outcome of the adaptive algorithm for intestinal slow wave with normal intestinal rate (upper left), abnormal slow intestinal rate (lower left), abnormal fast intestinal rate (upper right), and abnormal slow and fast intestinal rate (lower right). The dotted lines represent the start and end of the detection window with reference to the last detected peak. The blue dots are the detected peaks, and the red arrows correspond to the delivered peak stimuli

3 Results

3.1 Ground truth and λ estimation from AMPD

Figure 5 illustrates the estimation of peaks in offline mode using the AMPD. Those peaks are estimated after deriving the optimal scale λ. For all the given slow waves datasets, λ was found to be consistent for a given animal: 150 ± 0.04 (ms).

Fig. 5
figure 5

Illustration of the ground truth peak estimation of the intestinal slow wave of a rat from AMPD. The maximal optimal scale is illustrated to showcase the methods in which the peaks are estimated

3.2 Online peak detection algorithm

Figure 6 illustrates the result of the online peak detection algorithm for rats (β = 100 ms). For rodent slow waves, the detected peaks can be located before the ground truth peaks due to the occasional occurrence of sub-peaks that are adjacent to the ground truth peaks.

Fig. 6
figure 6

Peak detection algorithm results for rats with β = 100 ms

Figure 7 illustrates the different statistics of the accuracy of the peak detection algorithm assessed on the 10 datasets of the intestinal slow waves of the rats for λ = 150 ms and two values of β: 100 ms and 150 ms.

Fig. 7
figure 7

Boxplot illustration for the online peak detection algorithm on the intestinal slow waves of rats for different noise levels and lag values (n = 10)

Table 2 illustrates the results of the mean and standard deviation of the presented peak detection algorithm on intestinal slow waves in rats-5 during fasting and postprandial periods. The mean and standard deviation are calculated based on the presented results in Table 1.

Table 2 The mean and standard deviation of the presented peak detection

The overall accuracy is overall higher for the rat at 150 ms of lag compared to 100 ms when no white noise is added. However, for additional noise levels, the algorithm with the higher lag levels performed slightly worse.

3.3 Memory consumption and computational complexity

In terms of memory consumption, the dynamical memory allocations are restricted to the array buffer that stores the time signal values. The size of the buffer depends on λ and β, and the sampling frequency. With a float size of 4 bytes, β equal to 10% of cycleupper, and a sampling frequency of 20 Hz, the detection algorithm uses a buffer length of 33 ms and buffer size of 132 bytes.

3.4 Application of the proposed SIES

The above peak detection algorithm and the SIES system were applied in a rodent model of acute hyperglycemia under an animal research protocol approved by the Institutional Animal Care and Use Committee at University of Michigan. Under general anesthesia of 2% isoflurane, twelve male Sprague–Dawley rats were surgically implanted with two pairs of electrodes at the duodenum for the detection of slow waves and delivery of stimulation [8]. The electrode connecting wires were subcutaneously tunneled and externalized at the back of the neck. Upon a fully recovery from the surgical procedure and 5 h of fasting, the animals were injected (i.p.) with glucagon (0.5 mg/kg, Sigma-Aldrich) to induce acute hyperglycemia. Immediately after this, glucose (40%, 2 g/kg of body weight) was given by gavage to investigate the oral glucose tolerance. Blood samples of 10 µl were collected via the tail vein at 0 (before gavage), 15, 30, 60, 90, and 120 min after the glucose ingestion. Blood glucose was assessed using a glucometer. This test was performed in three randomized sessions on separate days, one with SIES using the developed system, one with regular IES, and the other with sham-SIES (same setup but no stimulation). In the session with SIES, the intestinal slow wave was recorded from the proximal pair of electrodes using the method described in “Methods”. A train of pulses (duration of 0.3 s, frequency of 40 Hz, pulse width of 3 ms, and amplitude of 2 mA) was delivered to the small intestine via the distal pair of electrodes upon the detection of each slow wave peak using the developed peak detection algorithm. The SIES was performed during the entire 120 min. The regular IES was delivered using the same train of pulses at an interval of 1.5 s or a rate of 40 trains/min, which was the same as the mean frequency of the small intestinal slow waves.

The following results were obtained: (1) the developed real-time detection of intestinal slow wave peaks and delivery of IES in synchronization with the slow wave peaks were assessed by visual inspection, which revealed an accuracy of above 90%. (2) Compared to sham, IES and SIES significantly reduced postprandial blood glucose at 30 min by 17% and 20% (one-way ANOVA followed with Tukey’s test), respectively. SIES but not IES showed a further inhibitory effect at 60 min (147 vs. 171 mg/dl, P = 0.001, vs. sham), demonstrating that SIES was more effective than IES.

4 Discussion

We have presented a peak detection algorithm that has several distinctive features: (1) different from most of existing algorithms, our algorithm is on-line and can be used for real-time peak detection; (2) a few parameters associated with the performance of the algorithm can be easily determined based on the characteristics of the small intestinal slow waves that are known to users; (3) the algorithm has been successfully applied for SIES, resulting in a better performance in suppressing postprandial blood glucose in a rodent model of acute hyperglycemia.

The AMPD was used as a method for deriving the optimal scale λ and the ground truth peaks. The parameter λ was found to be consistent across different datasets and correspond to the cycleavg value for a given animal (relatively small error of 5.33%). Thus, the optimal scale for detection corresponds to the average fluctuation range of the intestinal slow waves. Overall, λ can be estimated a priori for a given subject either from literature (knowledge of the mean frequency of the small intestinal slow waves of the corresponding species) or from the baseline small intestinal slow wave recording of the subject. Concerning the ground truth peaks, the AMPD was proven to be a robust method for automating the annotation process of the peaks (see Fig. 7). Nevertheless, the lack of consensus on which peaks can be considered the ground truth peak can be an element of future studies.

In the presented paper, the intestinal slow wave in rats has two general features: (1) basic noise with a general mean, (2) maximum peaks that significantly deviate from the noise. Furthermore, assuming that (a) the width of the peak cannot be determined in advance, (b) the height of the peak deviates significantly from other values, and (c) the algorithm is updated in real time based on λ/2. With the algorithm presented, the comparison can be performed only at left side of λ/2. This is a problem on the right side, as if λ/2 is large enough, it will create a delay between the start of the peak and the estimated time. In these situations, one needs to generate a boundary value that triggers the signal. However, the boundary value cannot be static and must be determined in real time based on an algorithm. If the new data point is x general deviations away from a moving average, the algorithm sends a signal. The algorithm is very robust because it produces separate moving averages and deviations so that the signal does not exceed the threshold. Therefore, future signals will be recognized with about the same accuracy, regardless of the number of previous signals. The algorithm takes three inputs. For example, if the lag is 5, use the last 5 observations to smooth the data. If the data points are 3.5 standard deviations away from the moving average, the threshold 3.5 is notified. Also, the effect of 0.5 gives the signal half the effect of a normal data point. Also, the effect of 0 completely ignores the signal for recalculating the new threshold. Therefore, the effect of 0 is the most stable option. Setting the influence option to 1 is at least stable. For non-stationary data, the impact option should be set between 0 and 1.

Periodical artifacts are common in biomedical signal processing or peak detection [42.43]. In our case, these include electrical cardiac signal and respiration artifacts. The cardiac signal is of a frequency of about 400 beats/min [43] and largely filtered out by the amplifier. The respiratory artifact is of a frequency of about 80–100 beats/min (several times of intestinal slow waves). However, it is hardly present in the recording due to the use of bipolar recordings. Moreover, the intestinal slow wave recording is made using electrodes implanted in the muscle layer and is of high signal to noise ratio. Accordingly, the major interference in the recording is attributed to non-periodic motion artifacts.

For the estimation of the overall accuracy, the choice of the accuracy metric of the peak detection method (peaks that are located at distance ≤ 10% of the cycleavg from the ground truth peaks) implies that upon peak detection, the electrical stimulation will still occur at a very close distance to the peak. For the accuracy of estimation in the rat, it increased substantially for the noiseless signal from 100 to 150 ms. However, at a higher noise level, the accuracy is higher for a lower β level. This is attributed to the fact that the high frequency range of the white noise has a higher probability of inducing contamination in the values after the peak that affect the peak estimation method (Eq. 2). Those values will in turn have a higher amplitude than the actual peaks and thus the algorithm will fail to detect the peak (false negative) or might detect it at the contamination. It is thus important to note that increasing the lag does increase the overall accuracy if there is no substantial noise in the recording. Nevertheless, the algorithm will be implemented on a chip implant with a band pass filter of (0.05–35 Hz); this implies that the effect of white noise should not be an issue in real-time peak estimation.

The SIES method was compared with regular IES in its inhibitory effect on blood glucose and found to be more potent than the regular IES, suggesting a great therapeutic potential for treating diabetes. The SIES system is currently being used for treating diabetes in two rodent models of T2D. An implantable pulse generator is being developed to accomplish the proposed SIES for humans.

The performance of peak detection algorithm in future human applications is expected to be much better for the following reasons: (1) the small intestinal slow wave in humans is of a frequency of 0.15 to 0.2 Hz, i.e., the peak-to-peak interval is about 5 s instead of 1.5 s in rats. This would allow more delay in peak detection and thus a higher accuracy; (2) the quality of intestinal slow waves in humans is higher, and the SNR is higher.

There are several limitations of the proposed algorithm. First, there is a time delay between the actual peak and estimated peak due to real-time processing. However, for the application of SIES, this delay is tolerable and does not affect the performance of SIES. Second, the user should be familiar with the characteristics of intestinal slow waves to determine a few parameters that are used in the algorithm.

5 Conclusion

This study presents a robust and effective online peak detection algorithm for small intestinal slow waves based on the AMPD technique. The developed algorithm has been validated using the small intestinal slow wave recording in rats and the entire SIES system has been applied to reduce postprandial hyperglycemia in rats and compared with sham stimulation and conventional IES. Our results demonstrated that the online peak detection provided a good overall accuracy while still respecting the requirements for low memory conservation and computational complexity. The fulfillment of those requirements makes the algorithm well suited for an implantable pulse generator to be used in future clinical applications.