1 Introduction

The occurrence in scalp electroencephalogram (EEG) of electrical artifacts generated by eye movement (EOG) is a well-recognized problem in EEG-based studies. To correct, or remove the ocular artifacts from the EEG, many regression-based techniques have been developed that include time-domain regression [5, 8, 11] and regression in the frequency domain [14, 16]. More recently, component-based techniques, such as principal component analysis (PCA) [9] and independent component analysis (ICA) [7, 12], have also been proposed to remove the ocular artifacts from the EEG. These methods are typically applied to EEG and EOG epochs (segments) that were recorded simultaneously. It has been shown that the choice of epoch length may affect the performance of the method, and special care needs to be taken in re-attaching the neighboring epochs after correction [13]. In addition, these methods are incapable of performing real-time, sample-by-sample removal of the EOG artifacts unless a fixed set of correction coefficients has been pre-determined from calibration trials [1].

We have recently proposed a new method for removing the ocular artifacts from the EEG that is based on an adaptive filtering technique [6]. The method has been implemented using a LabVIEW (National Instruments, TX, USA) program for real-time removal of the EOG artifacts during actual EEG data collection. Based on visual, qualitative inspection, the method is shown to be effective in removing both vertical and horizontal EOG artifacts from the EEG [6]. An alternative adaptive noise canceller was proposed by Erfanian and Mahmoudi [3] who replaced the linear adaptive filters by a recurrent neural network to produce an estimation of the noise component in the primary input.

The main purpose of this paper is to provide a more detailed analysis of the adaptive filtering (AF) method with a reference to the time-domain regression (TR) method, and to present a quantitative comparison between the accuracy of the two methods in recovering the true EEG. Specifically, we will prove that by setting the two parameters of the AF method, M (the length of the adaptive filter) and λ (the “forgetting factor”), both to one, the AF method becomes equivalent to the TR method. On the other hand, by allowing M to be larger than one, we will show, through a simulation study, that the AF method is more flexible that the TR method to accurately correct EEG if there is a shape difference (Throughout this paper, shape difference or waveform distortion refers to the change which cannot be produced by a simple scale-up or scale-down. An example is the widening or narrowing of an EOG pulse) or a misalignment (time delay) between the reference EOG and the EOG artifact in the EEG.

2 Method

2.1 A brief description of the AF method for removal of EOG artifacts

Figure 1 shows a block diagram of a noise canceller based on adaptive filtering. The primary input to the noise canceller is the EEG signal, y(n), picked up by a particular electrode (e.g. F7) where n is the sample number. This signal is modeled as a mixture of a true EEG, x(n), and a noise component, z(n). r v (n) and r h (n) are the two reference inputs, VEOG (vertical EOG) and HEOG (horizontal EOG), respectively. h v (m) and h h(m) represent the mth coefficients of two FIR (finite impulse response) filters of length M (the two filters can have difference lengths). The output e(n) from the noise canceller is the corrected EEG, e(n):

$$ e(n) = y(n) - v(n) - u(n) $$
(1)

where

$$ v(n) = {\sum\limits_{m = 1}^M {h_{{\text{v}}} (m)\,r_{{\text{v}}} (n + 1 - m)} }\quad {\text{and}}\quad u(n) = {\sum\limits_{m = 1}^M {h_{{\text{h}}} (m)\,r_{{\text{h}}} (n + 1 - m)} } $$
(2)

are the filtered reference signals.

Fig. 1
figure 1

Block diagram of EOG noise canceller using adaptive filtering with two reference inputs

There are two parameters in the AF method, M and λ. M is the length, or the number of coefficients, of the two filters, and λ is the forgetting factor. Assuming at time t n we have collected, cumulatively, the following samples: y(i), r v (i), and r h(i) for i = 1, 2, ..., n, we form the following weighted squares ε(n):

$$ \varepsilon (n) = {\sum\limits_{i = M}^n {\lambda ^{{n - i}} e^{2} (i)} } = e^{2} (n) + \lambda e^{2} (n - 1) + \cdots + \lambda ^{{n - M}} e^{2} (M) $$
(3)

where 0 < λ ≤ 1 and

$$ e(i) = y(i) - {\sum\limits_{m = 1}^M {h_{{\text{v}}} (m)\,r_{{\text{v}}} (i + 1 - m) - } }{\sum\limits_{m = 1}^M {h_{{\text{h}}} (m)\,r_{{\text{h}}} (i + 1 - m)} } $$
(4)

The method calls for minimizing ε(n) by adjusting the filter coefficients h v and h h. This set of filter coefficients is then used in Eqs. (1) and (2) to calculate e(n) which becomes the current sample of the corrected EEG. When y(n + 1), r v (n + 1), r h(n + 1) are recorded at t n+1, a new set of filter coefficients is calculated that minimizes the new weighted squares function ε(n + 1), and a corrected EEG sample, e(n + 1), is obtained. Since the change from ε(n) to ε(n + 1) is incremental, updating of filter coefficients is also incremental. As a result, the method can be implemented by a recursive algorithm (called recursive least squares—RLS method) that is very efficient and fast.

Since the AF method and the TR method are both based on an analysis of the correlation between the reference EOG and the EOG artifacts in the EEG, there must be an intrinsic relationship between the two methods. In fact, it can be proved that when λ = M = 1, the two methods are basically identical (see Appendix).

2.2 The role of the forgetting factor λ

To explain the role of the forgetting factor λ, we use the block diagram in Fig. 2 to model the generation and removal of EOG artifacts. Without the loss of generality, here we only consider a single source EOG, e.g. the vertical EOG.

Fig. 2
figure 2

A model for generation and removal of EOG artifacts

In Fig. 2, transfer of the source EOG to the EEG channel is modeled by a transfer function F. The reference EOG used for removing EOG artifacts in both the TR method and the AF method is the measured EOG. Although transfer of the source EOG to the EEG channel may be considered stationary, the electrical characteristics of the electrodes and amplifiers may change with time (e.g. the contact impedance between the electrode and the skin may change with time). As a result, the correlation between the reference EOG and the EOG artifact in the measured EEG may not be stationary. If the removal of the EOG artifacts is based on a fixed set of transmission (correction) coefficients, which were pre-determined from calibration trials [1], the performance of the TR method will be deteriorated due to this non-stationarity. If the regression is applied to the current epoch, the performance of the TR method is immune from this problem, but at the sacrifice of real-time, sample-by-sample artifact removal. The AF method addresses this problem by introducing a forgetting factor 0 < λ < 1. As defined by Eq. (3), calculation of the optimal filter coefficients is based on a weighted squares term ε(n): more recent samples have larger weights in determining the optimal filter coefficients. Using a rough analogy, the value of λ in the AF method corresponds to the epoch length in the TR method. However, in the AF method, there is no clear (epoch) boundary and the problem of non-stationarity is addressed without sacrificing the capability of real-time artifact removal.

2.3 The role of M: a simulation study

2.3.1 Description of the simulation study

In our previous study [6], since the true EEG was unknown, the performance of the AF method was judged by a visual comparison between the corrected EEG waveforms and the EEG waveforms that did not contain noticeable EOG artifacts. To quantitatively evaluate the accuracy of the AF method in recovering the true EEG, a simulation study is conducted.

Figure 3 shows the block diagram of the model used in the simulation study. In comparison with Fig. 2, the only difference is that the two blocks representing the electrodes and amplifiers are not present in Fig. 3 (as a result, source EOG ≡ reference EOG), as the problem of non-stationarity has been discussed in the previous section and therefore is not considered in the simulation study.

Fig. 3
figure 3

The model used in the simulation study. z represents the EOG artifacts mixed into the EEG

The main difficulty in a simulation study is to accurately reproduce the actual process of the true system. In the present simulation, the main question is how to simulation the transfer function F in Fig. 2. One may reasonably assume that this function is linear, causal and stationary. Other than that, any additional assumptions about this transfer function require careful justification.

Based on the theory of linear systems, the characteristics of this transfer can be generally described by a frequency-domain, complex function F(f) which can be separated into two functions:

$$ F(f) = A(f)\angle \phi (f) $$
(5)

where A(f) represents the gain (magnitude) function and φ(f) is the phase function (angle). In the TR method that uses a constant transmission coefficient, it is implicitly assumed that A(f) is frequency independent. The validity of such an assumption is questionable. For example, Gasser and co-workers [4] used a frequency domain approach to study the transfer of the EOG activity into the EEG for both eyes open and eyes closed, and found that A(f) was significantly frequency-dependent. Since a frequency-dependent model is more general than a frequency-independent model, in our simulation, we will use a frequency dependent gain function A(f), as shown in Fig. 4, that is constructed based on the data published by Gasser et al. [4].

Fig. 4
figure 4

The gain function A(f) used in the simulation

There is little information regarding the phase angel φ(f) of the EOG transfer. In theory, when a signal passes through a causal system, there will always be a phase change. The simplest case is when φ(f) is a linear function of frequency. In such a case, the effect of φ(f) becomes a simple propagation delay. In practice, the speed of EOG propagation may be so high that the propagation delay becomes negligible [4]. On the other hand, modern EEG processing involves various digital filtering that may introduce noticeable time delay, or misalignment, between the reference EOG and the EOG artifact in the EEG. For example, a common concern in removing the EOG artifacts is bidirectional contamination. To remove the EEG component in the EOG, low-pass filtering the EOG signal was suggested [10]. To demonstrate the possible time delay produced by such a filtering, we used a third-order elliptic low-pass filter (MATLAB function [B, A] = ellip(3, 1, 20, 40/fs) where fs = 256 Hz is the sampling frequency) to filter a single EOG pulse, and the result is shown in Fig. 5.

Fig. 5
figure 5

The effects of low-pass filtering of EOG pulse. The peaks of the original (solid line) and filtered EOG (dashed line) are both normalized to one to emphasize the relative shift between the two pulses

As one can see from Fig. 5, the small ripples corresponding to the EEG component are effectively removed by the filter. But the filter also causes a four-sample shift (delay) of the filtered pulse relative to the original pulse. If such a filtered EOG is used for the regression analysis, the reference EOG and the EOG artifact in the EEG will not be aligned perfectly. In our simulation, we refer such a waveform shift as a negative delay because the EOG artifact in the EEG is ahead of the reference EOG. Similarly, a bandpass filter is commonly used to process the recorded EEG for removing the baseline drift and muscle noise. If such a filter produces a noticeable waveform shift, the EOG artifact in the EEG will be behind the reference EOG. In our simulation, we refer such a waveform shift as a positive delay. Since the exact degree of misalignment between the reference EOG and the EOG artifact in the EEG in an actual experiment is difficult to determine, in our simulation study, we arbitrarily choose the amount of misalignment as either a positive or negative delay of two samples (about 8 ms at a sampling frequency of 256 Hz) and such delays will be produced by the transfer function F in Fig. 3.

The block diagram of the model used in the simulation study is shown in Fig. 3, where all the possible differences between the reference EOG and the EOG artifact in the EEG are produced by a transfer function F. By choosing suitable forms of F, four cases are simulated in this study:

  • Case 1: F = A(f) which is plotted in Fig. 4, and no delay (∠φ(f) = 0)

  • Case 2: F = 0.2 ∠φ+(f) where φ+(f) produces a positive delay of two samples.

  • Case 3: F = 0.2 ∠φ(f) where φ(f) produces a negative delay of two samples.

  • Case 4 = Case 1 + Case 2: F = A(f) ∠φ+(f) where A(f) is the same one used in Case 1 and φ+(f) is the same one used in Case 2.

2.3.2 True EEG used in the simulation study

Raw EEG waveforms were selected from the database previously collected in an experiment in which the operator was performing the tasks specified by the multi-attribute task battery (MATB) interactive software developed by NASA [2]. Standard 19-channel EEG recording was performed and all the EEG channels were referenced to the right mastoid. In addition, a pair of electrodes was placed above and below the right eye to record VEOG, and another pair of electrodes was placed at the left and right outer canthi of the eyes to record HEOG. All signals were band-pass filtered at 0.48–30 Hz and sampled at 256 Hz. From the EEG signals recorded at Pz and O2 channels which were far from the EOG sources, 50 epochs, each containing 1,280 samples (5 s duration) were selected during the periods without noticeable EOG activity. Each waveform was then normalized to have a zero mean and a variance of one. These 50 waveforms were used as the true EEG.

2.3.3 Source or reference EOG

From the same database, 10 VEOG pulses were selected, each containing 385 samples with the peak located near the center. Smoothing spline (MATLAB, Spline toolbox) was applied adaptively to remove the high frequency noise in the low amplitude region without distorting the waveform in the high amplitude region. These 10 EOG pulses were used as the seeds to generate 50 source EOG waveforms. Each source EOG waveform contained four EOG pulses that were randomly selected from the ten seed EOG pulses. The amplitude of each pulse was scaled by a random factor that was uniformly distributed between 0.8 and 1.2, and the locations of the four pulses were also randomized based on a Poisson distribution. The end points of each pulse were adjusted to ensure smooth transition from one EOG pulse to the next, and extra samples were removed so that each source EOG waveform also contained a total of 1,280 samples (5 s). Finally, a single scale factor was used to adjust the magnitude of the source EOG waveform so that the simulated noisy EEG waveforms resemble those recorded at a frontal EEG channel such as F7.

Figure 6 shows five true EEG waveforms and one source EOG waveform (scaled down for the purpose of plotting) that were used in the simulation study.

Fig. 6
figure 6

(15): Five examples of true EEG waveforms used in the study. (6) a scaled-down example of source (reference) EOG used in the study

2.3.4 Simulation of noisy EEG

  • Case 1: the transfer function has zero-phase [φ(f) = 0] and a low-pass gain function A(f)

Based on the results published by Gasser et al. [4], a ninth order IIR (infinite impulse response) filter was designed using MATLAB function “yulewalk”. The actual gain function of the filter is plotted in Fig. 4.

To apply this frequency-dependent filtering without producing any phase shift or delay, the MATLAB function “filtfilt” was used to filter each of the 50 source EOG waveforms. Each filtered EOG waveform was then added to one of the 50 true EEG waveforms to produce one of the 50 simulated noisy EEG waveforms. An example of a pair of the true EEG and the simulated noisy EEG is shown in Fig. 7.

  • Case 2: Each source EOG waveform was first shifted to the right (positive delay) by two samples, scaled down (multiplied) by a factor of 0.2, and then added to a true EEG waveform to produce a simulated noise EEG.

  • Case 3: Each source EOG waveform was first shifted to the left (negative delay) by two samples, scaled down by a factor of 0.2, and then added to a true EEG waveform to produce a simulated noise EEG.

  • Case 4 (Case 1 + Case 2): Each source EOG waveform was first shifted to the right by two samples, filtered by the zero-phase low-pass filter described in Case 1, and then added to a true EEG waveform to produce a simulated noise EEG.

Fig. 7
figure 7

Shown are one set of examples of the simulated noisy EEG (1) in Case 1, the true EEG (2), the corrected EEG using the AF method (M = 3) (3), and the corrected EEG using the TR method (4). Waveforms (24) have the same scale while waveform (1) is plotted using a different scale

3 Results

The TR method and the AF method were applied to each set of a simulated noisy EEG waveform, denoted by y(n), and the corresponding reference EOG waveform, to produce the “corrected” EEG, denoted by e(n). For the AF method, the forgetting factor λ = 1, and the filter length M was changed from 1 to 5.

Figure 7 shows a set of examples obtained in the simulation for Case 1. From top to bottom, the four waveforms represent the simulated noisy EEG (1), the true EEG (2), the corrected EEG using the AF method when M = 3 (3) and the corrected EEG using the TR method (4). It is noticeable that waveform (3) resembles waveform (2) more accurately than waveform (4).

To quantitatively compare the accuracy of the two methods in recovering the true EEG, a time-domain analysis and a frequency-domain analysis were employed. In the time-domain analysis, a mean squares error (MSE) is defined as:

$$ {\text{MSE}} = {\sum\limits_{n = 1}^N {[e(n) - x(n)]^{2} } }/N $$
(6)

where e(n) and x(n) represent the corrected and true EEG, respectively, and N = 1,280 is the total number of samples in each simulated waveform. Using Eq. (6), the MSE was first calculated for each pair of waveforms [x(n) and e(n)], and the results from all 50 pairs of waveforms were then averaged.

In the frequency-domain analysis, the power spectral density of the true EEG and the corrected EEG were first calculated using the MATLAB function “pburg” based on a fifth order autoregression model. A mean absolute error (MAE) is defined for each of the four bands: Δ band (f < 4 Hz), θ band (4 ≤ f < 8 Hz), α band (8 ≤ f < 13 Hz), and β band (13 ≤ f < 30 Hz) according to Eq. (7):

$$ {\text{MAE}} = {\sum\limits_{n = i}^j {{\left| {P_{e} (n) - P_{x} (n)} \right|}} }/(j - i) $$
(7)

where P e and P x are the power spectral density functions of e(n) and x(n), respectively, and i, j define the frequency range of a particular band. Again, for each band, MAE was first calculated for each pair of waveforms [x(n) and e(n)], and the results from all 50 pairs of waveforms were averaged.

The results of the time-domain analysis for the four cases are summarized in Table 1, while the results (enlarged by 10 times) of the frequency-domain analysis for Cases 1, 2, and 4 are reported separately in Tables 2, 3, and 4 (the results of Case 3 are not presented because they are very similar to that of Case 2). From Table 1, one can see that when M = 1, the results from the AF method are rather close to that of the TR method, which is consistent with our earlier analysis that showed when λ = M = 1, the two methods were equivalent. The still-existing difference is due to the fact that the TR method was applied to the entire 1,280 samples at once while in the AF method, the filter coefficients were updated, and the EEG was corrected, sample by sample. In Case 1 and Case 4, the MSE drops significantly at M = 3 (the corresponding MSE values are shown in bold in Table 1) and changes little thenafter. In Case 2 and Case 3, such a significant drop takes place at M = 2 (the corresponding MSE values are shown in bold in Table 1). The average filter coefficients at the end of each run (a total of 50 runs) are: Case 1, M = 3: (5.0374, −9.6340, 4.8605); Case 2, M = 2: (−0.1813, 0.3804); Case 3, M = 2: (0.6047, −0.4080); Case 4, M = 3: (4.8734, −9.6257, 5.0161).

Table 1 Time-domain analysis: mean squares error (MSE) of the two methods in four cases
Table 2 Frequency-domain analysis for Case 1: 10 × MAE in Δ, θ, α, and β bands
Table 3 Frequency-domain analysis for Case 2: 10 × MAE in Δ, θ, α, and β bands
Table 4 Frequency-domain analysis for Case 4: 10 × MAE in Δ, θ, α, and β bands

Similar observation can be made from the results of the frequency-domain analysis. In each case, when M = 1, the mean absolute error (MAE) of the two methods are comparable in each of the four bands. For Case 1 and Case 4, the MAE of the AF method becomes significantly lower than that of the TR method for M ≥ 3 in each of the four frequency bands. For Case 2 and Case 3, this happens when M ≥ 2.

4 Discussion

The fact that the AF method becomes equivalent to the TR method when M = λ = 1 indicates that there is an intrinsic relationship between the two methods, and the TR method can be considered as a special case of the AF method. A useful suggestion comes from this relation is that the forgetting factor λ and the recursive least-squares algorithm used by the AF method can also be adopted by the TR method to achieve real-time, sample-by-sample removal of EOG artifacts while also deal with the possible non-stationary correlation between the reference EOG and the EOG artifacts in the measured EEG.

The fundamental difference between the AF method and the TR method is associated with the parameter M. Let us now explain why in our simulation the AF method can achieve a more accurate EOG correction by using an M that is larger than one.

Figure 8 presents a block diagram that combines the process of EOG contamination, previously described in Fig. 3, with the process of EOG removal used by both the AF and the TR methods. In the figure, z represents the transferred EOG that becomes the EOG artifact in the EEG, and v is transformed from the reference EOG and is then subtracted from the noisy EEG to obtain the corrected EEG. Obviously, if v is exactly equal to z, the corrected EEG will be exactly equal to the true EEG. In fact, both methods try to produce a v that is as close to z as possible. If z is proportional to r, the TR method, as well as the AF method, can completely remove the EOG artifact. On the other hand, if z is not proportional to r, as in the four cases simulated in this study, the AF method can produce much smaller errors than the TR method, as indicated by the results in Table 1 to Table 4. The reason for this is that in each of these four cases, the AF method, by using a suitable M, can produce a v that is much closer to z than the TR method can. To demonstrate this fact, we chose a single EOG pulse, processed the pulse using the transfer function F (four different cases), and compared the transferred pulse (z) with a pulse (v) that is transformed by the AF method. The results for Case 4 are shown in Fig. 9.

Fig. 8
figure 8

The combined model describing generation and removal of EOG artifacts using both AF and TR methods. u represents the EOG artifacts mixed into the EEG and v represents the estimated EOG artifacts to be subtracted from y

Fig. 9
figure 9

Original EOG pulse (solid line), filtered pulse (dashed line), and the transformed pulse (dotted line) obtained by the AF method for Case 4. The maximum values of the original and transferred pulses are normalized to one for the purpose of comparison

In Fig. 9, the black solid line represents the original pulse with the maximum value normalized to one. The red dashed line is produced by the filter that has a frequency dependent gain function A(f) shown in Fig. 6, and then delayed by two samples. The blue dotted line, whose maximum value is also normalized to one, is produced by a third-order FIR filter with h(1) = 4.8734, h(2) = −9.6257, and h(3) = 5.0161. Comparing with the original pulse (the solid line), the transferred pulse (the dashed line) has a changed shape (becomes wider) and a time delay. Obviously, one cannot closely approximate the transferred pulse by scaling the original pulse. On the other hand, the transformed pulse (the dotted line) produced by the AF approximates the transferred pulse reasonable well. This explains why the AF method produces a smaller residual error than the TR method in removing the EOG artifact.

It should be pointed out that although we used a transfer function shown in Fig. 4 in our simulation, it is just for the purpose of producing a shape change based on a documented work [4]. It does not represent our assertion that EOG transfer is indeed frequency-dependent, an issue that is still under debating. In fact, the AF method itself does not depend on such an assumption (that EOG transfer is frequency dependent). It just sees the shape change and tries to duplicate such change. Such a shape change could be produced by a frequency-dependent EOG transfer; it could be produced if one uses different filters to process the EEG and EOG, or it may be produced by other mechanisms that are not fully understood (for example, it was shown that the shape of the ECG recorded by the chest leads was significantly different from that recoded by the abdominal leads [15]). It should also be pointed out that not all digital processing introduces temporal shift or time delay. For example, the free-knot spline technique used by Wallstrom et al. [13] to smooth the EOG signal, as well as the special MATLAB function “filtfilt” used in the current simulation, do not introduce time delays. But any causal filters will produce a certain degree of time delay. Finally, the misalignment between the reference EOG and the EOG artifact in the EEG can be avoided if one applies exactly the same filter to both signals. However, since the EOG and EEG occupy different frequency ranges, requiring the use of the same filter to process both signals becomes an undesirable limitation that may not always produce the optimal result in various applications. The real advantage of the AF method therefore, is its flexibility or adaptability. Whether the EOG transfer is frequency dependent or frequency independent, whether there may be other mechanisms that cause a shape difference between the reference EOG and the EOG artifact in the EEG, whether the reference EOG is ahead or behind the EOG artifact in the EEG, the AF method can always transform the reference EOG to a waveform that closely resembles the artifact in the EEG, and then to cancel it effectively. Best of all, this optimal noise cancellation is performed automatically (e.g. M = 3 can be used for all the cases simulated in this study) and in real time.

Not considered in the simulation study is the phenomenon known as bidirectional contamination. The performance of the AF method will also be deteriorated when the reference EOG contains significant EEG components. Therefore, a preprocessing of the reference EOG, such as using free-knot splines to adaptively smooth the reference EOG [13], may be beneficial. Finally, although only one EOG source is considered in the current simulation study, all the conclusions obtained in this study can be extended to the case where more than one EOG inputs are involved.