An Improved Signal Segmentation Using Moving Average and Savitzky-Golay Filter ()
1. Introduction
Biomedical signals such as electroencephalogram (EEG) and electrocardiogram (ECG) are usually known as nonstationary signal i.e. its statistical characteristics change over the time [1]. The purpose of the segmentation signal is dividing a signal to several epochs with the same statistical characteristics such as amplitude and frequency [2, 3]. Since Analysis of stationary signal is easier than nonstationary signal, signal segmentation is usually applied as pre-processing step for non-stationary signal analysis.
There are two kinds of signal segmentation, namely, constant segmentation and adaptive segmentation. In constant segmentation signal is segmented to fixed epochs [4]. Although constant segmentation is simple and easy in case of implementation, this method has small reliability. Inasmuch as the duration of the signal segments isn’t usually equal, today signal segmentation is performed automatically that it is named adaptive segmentation [1]. In [5-11] different methods of adaptive segmentation can be seen.
In Modified Varri method two sliding windows are used. This method is based on combination of a frequency measure estimated by the sum of the difference of consecutive signal samples and an amplitude values of the signal in the relevant windows as follows [1]:
(1)
(2)
where l and xk are the window length and the kth signal point, respectively. Thus, the measure difference function (G) is defined as below:
(3)
where m is the number of the window; A1 and F1 are constant coefficients which change in various applications. Local maxima in the G function, above a threshold that is defined before, specify boundaries of the segments [1].
Real data usually contains noise. When data is noisy, in many applications such as signal segmentation may not be completely analyzed correctly. Therefore, decreasing noise in experimental time series is an important issue. This issue has become increasingly important in health sciences, systems biology, nano-sciences, information systems, and physical sciences [12]. Filters and smoothers not only can reduce destructive noise and short-term components of a signal, but also these can increase the speed of the simulation.
Since simple moving average (MA) is the easiest digital filter to understand and use, it is the most common filter in analysis a signal. In spite of its simplicity, the MA filter is optimal for a common task such as reducing random noise. The Savitzky-Golay filter is an effective tool for de-noising and smoothing a signal. The obtained outputs of Savitzky-Golay filter demonstrate the filtered signal contains less noise than the original signal and exhibits less distortion than moving average filtering technique of the same order [13-15]. In this paper in order to increase the accuracy of Modified Varri, MA and SavitzkyGolay filter are used. After filtering the signal, Modified Varri which is a powerful method for segmenting a signal is applied.
This paper is organized as follows. Next section explains MA and Savitzky-Golay filters. In the third section the proposed method is described briefly. The performance of the suggested method is evaluated by synthetic data and real EEG signal which is represented in Section 4. Finally, Section 5 provides conclusion.
2. Background Knowledge for the Proposed Method
2.1. Moving Average Filter
One of the most common tools for smoothing data is the MA filter, often used to try to capture important trends in repeated statistical surveys. This approach that is known as a type of Finite Impulse Response (FIR) filter is applied to a set of data points by creating an average of different subsets of the full data set. In this paper MA is defined for samples as follows:
(4)
where x(n) is the original signal.
2.2. Savitzky-Golay Filter
The Savitzky-Golay filter is a powerful tool for smoothing a signal that was proposed by Savitzky and Golay in 1964. The filter is defined as a weighted moving average with weightening given as a polynomial of specific degree [13-15]. The coefficients of a Savitzky-Golay filter, when applied to a signal, perform a polynomial P of the degree k, is fitted to points of the signal, where N describes window size. Nr and Nl are signal points in the right and signal points in the left of a current signal point, respectively [13-15]. One of the best advantages of this filter is that it tends to keep features of the distribution such as relative with, maxima and minima which are often flattened by other smoothing techniques such as MA [13-15].
3. Proposed Method
Proposed method is a three-stage procedure that is described below:
1) First the original signal is filtered by MA or Savitzky-Golay filter to represent the important underlying unadulterated from of the time series by attenuating its short-term variations. The MA is very fast and it can be implemented simply. The main advantage of SavitzkyGolay filter is that it tries to preserve the features of time series such as its relative minima and maxima, which it is very important issue in segmentation a signal. Unlike wavelet, these filters don’t have shifting effect after filtering the signal which is very important characteristic to detect true boundaries of epochs. Mathematically, these filters described in Section 2.1 and 2.2, respectively.
2) As mentioned before, two sliding windows move along the signal and for each window G is determined to find the boundaries of the signal segments. the G variations are computed as follows:
(5)
where m is the number of the window; A1 and F1 are constant coefficients which change in various applications.
3) Local maxima in the G function, above a threshold, the mean value in the distribution of the G defined before, identify the boundaries of the segments.
4. Performance Evaluation
The following methods were implemented using MATLAB R2009a from Math Works. The performance and efficiency of these methods were evaluated using 50 synthetic multi-component data, and real EEG data.
4.1. Synthetic Signal
For assessing the performance of the suggested methods, these algorithms are applied on a set of synthetic multicomponent signals which each epoch is selected as a stationary signal. One piece of these signals includes the following seven epochs:
Epoch 1: 0.5cos(πt) + 1.5cos(4πt) + 4cos(5πt)Epoch 2: 0.7cos(πt) + 2.1cos(4πt) + 5.6cos(5πt)Epoch 3: 1.5cos(2πt) + 4cos(8πt)Epoch 4: 1.5cos(πt) + 4cos(4πt)Epoch 5: 0.5cos(πt) + 1.7cos(2πt) + 3.7cos(5πt)Epoch 6: 2.3cos(3πt) + 7.8cos(8πt)Epoch 7: 0.8cos(πt) + cos(3πt) + 3cos(5πt).
Figures 1(a) and (b) show 50 seconds of original signal and the result of applying simple Modified Varri, respectively. Figure 1(b) dedicates that this algorithm cannot detect one segment boundary of the signal. Also, obtained output shows this method has three False Boundaries (FBs). The threshold value for this method is chosen mean value of obtained output.
Figure 1. Signal segmentation in synthetic signal. (a) Original signal; (b) Output of the simple Modified Varri (window length = 2 s, A1 = 7 and F1 = 1).
The signal in Figure 1(a) is also segmented using Modified Varri with MA as a pre-processing step (Figure 2). Also in Figure 3, Savitzky-Golay filter is applied as a pre-processing step. In this paper, for synthetic data, we have used an order 3 polynomial SavitzkyGolay filter and the frame size of 9 samples. As can be seen in Figures 2(c) and 3(c), the boundaries for all seven segments can be accurately detected. In order to make the signals more similar to real signals, Gaussian noise is added to original signal and then the performance of the proposed methods are assessed. In this paper 50 synthetic multi-component signals are used.
Three parameters are used to assess the performance of the proposed methods: True Positive (TP) Miss or False Negative (FN) and False Alarm or False Positive (FP) ratios. These parameters are shown follows:
where Nt, Nm and Nf represent the number of true, missed, and falsely detected and N shows actual number of segment boundaries.
In Table 1 the results of segmentation for 50 synthetic data using the proposed methods are shown next to the results of simple Modified Varri method. The obtained results indicate which those proposed methods using filters such as MA and Savitzky-Golay as a pre-processing step can improve TP, FN, and FP ratios. As can be seen in Table 1, TP, FN and FP ratios obtained of Modified Varri with Savitzky-Golay filter are better than Modified Varri with MA filter. By using Savitzky-Golay filter we can achieve TP and FP ratios equal to 100% and 24% on a set of 50 synthetic signals without noise, respectively.
Table 1. Effect of applying proposed methods and existing methods on set of synthetic data.
4.2. Real EEG
Electroencephalography (EEG) is the neurophysiologic measurement of the electrical activity of the brain using electrodes which are placed on the scalp [4]. As described before, signal segmentation is a pre-processing step for EEG signals. In this part we have used a real newborn EEG signal that is shown in Figure 4(a). The length of this signal and the sampling frequency are 500 milliseconds and 256 Hz, respectively.
The result of applying simple Modified Varri and Modified Varri with Savitzky-Golay filter is shown in Figures 4(b) and 5(c), respectively. In this paper, for real
Figure 2. Signal segmentation in synthetic signal. (a) Original signal; (b) Filtered signal by MA; (c) Output of the Modified Varri (window length = 2 s, A1 = 7 and F1 = 1). As can be all seven segments can be truly detected.
Figure 3. Signal segmentation in synthetic signal. (a) Original signal; (b) Filtered signal by Savitzky-Golay filter; (c) Output of the Modified Varri (window length = 2 s, A1 = 7 and F1 = 1).
Figure 4. Signal segmentation in real EEG data. (a) Original signal; (b) Output of the simple Modified Varri (window length = 0.04 s, A1 = 7 and F1 = 1).
Figure 5. Signal segmentation in real EEG data. (a) Original signal; (b) Filtered signal by Savitzky-Golay filter; (c) Output of the Modified Varri (window length = 0.04 s, A1 = 7 and F1 = 1). As can be all five segments can be truly detected.
EEG data, we have used an order 3 polynomial SavitzkyGolay filter and the frame size of 51 samples. In Figure 5(c) can be seen that all five segments segmented accurately. It should be mentioned that simple Modified Varri could not detect one segment boundary of the signal. We can see the influence of this method compared with achieved outputs.
5. Conclusion
One of the existing methods for signal segmentation is Modified Varri. Because real signals usually include different noises, this method is unreliable for segmenting a signal. For overcoming this problem we use moving average and Savitzky-Golay filters. These filters reduce short-term noise for a signal that caused that the reliability of this method increased considerably. Although moving average filter is easier and simpler than Savitzky-Golay filter, but performance of using Savitzky-Golay filter is better than moving average. The results indicate that the Modified Varri method with moving average filter has better performance compared to the simple Modified Varri and the Modified Varri with Savitzky-Golay filter has better accuracy comparing with moving average filter.