Journal of Neuroscience Methods 109 (2001) 137– 145 www.elsevier.com/locate/jneumeth Stimulus artifact removal using a software-based two-stage peak detection algorithm Derek T. O’Keeffe a,*, Gerard M. Lyons a, Alan E. Donnelly b, Ciaran A. Byrne b a Biomedical Electronics Laboratory, Department of Electronic and Computer Engineering, Uni6ersity of Limerick, Limerick, Ireland b Department of Physical Education and Sports Science, Uni6ersity of Limerick, Limerick, Ireland Received 20 March 2001; received in revised form 30 May 2001; accepted 31 May 2001 Abstract The analysis of stimulus evoked neuromuscular potentials or m-waves is a useful technique for improved feedback control in functional electrical stimulation systems. Usually, however, these signals are contaminated by stimulus artifact. A novel software technique, which uses a two-stage peak detection algorithm, has been developed to remove the unwanted artifact from the recorded signal. The advantage of the technique is that it can be used on all stimulation artifact-contaminated electroneurophysiologic data provided that the artifact and the biopotential are non-overlapping. The technique does not require any estimation of the stimulus artifact shape or duration. With the developed technique, it is not necessary to record a pure artifact signal for template estimation, a process that can increase the complexity of experimentation. The technique also does not require the recording of any external hardware synchronisation pulses. The method avoids the use of analogue or digital filtering techniques, which endeavour to remove certain high frequency components of the artifact signal, but invariably have difficulty, resulting in the removal of frequencies in the same spectrum as the m-wave. With the new technique the signal is sampled at a high frequency to ensure optimum fidelity. Instrumentation saturation effects due to the artifact can be avoided with careful electrode placement. The technique was fully tested with a wide variety of electrical stimulation parameters (frequency and pulse width) applied to the common peroneal nerve to elicit contraction in the tibialis anterior. The program was also developed to allow batch processing of multiple files, using closed loop feedback correction. The two-stage peak detection artifact removal algorithm is demonstrated as an efficient post-processing technique for acquiring artifact free m-waves. © 2001 Elsevier Science B.V. All rights reserved. Keywords: Stimulus artifact; Artifact removal; Digital signal processing; M-wave; Electrical stimulation; EMG blanking; Electrophysiology 1. Introduction The recording and interpretation of myoelectric activity is a useful technique for understanding muscle activity for diagnostic, prognostic and therapeutic purposes (Solomonow et al., 1985). The electrically evoked myoelectric signals (m-waves) of paralysed muscles stimulated by surface electrodes is also of interest if the relationship between the electrical activity and the force within the stimulated muscle is to be investigated (Minzly et al., 1993). However, m-waves may have a stimulation artifact associated with them. This is true especially when surface electrodes are used to stimulate the tissue and to detect the resulting generated biopo* Corresponding author. Tel.: + 353-61-202443. E-mail address: derek.okeeffe@ul.ie (D.T. O’Keeffe). tentials. While experimental techniques have been developed which minimise the effect of stimulus artifact contamination, these techniques invariably leave residual artifact, which may interfere with analysis of the m-wave data (Parsa et al., 1998). The stimulus artifact is typically spike-shaped followed by an exponential decay (Fig. 1) whose amplitude and time constant is dependent on several factors (McGill et al., 1982). These factors include experimental technique, stimulator output stage, amplifier design, electrode orientation, stimulation type and electrode – skin interface. If the recording site is sufficiently far away from the stimulus location, then the artifact and the evoked physiological response will not overlap (Harding, 1991). The distance between the two sites will affect the conduction latency period (Fig. 1). A long, very slow exponential decay may offset the stimulus 0165-0270/01/$ - see front matter © 2001 Elsevier Science B.V. All rights reserved. PII: S 0 1 6 5 - 0 2 7 0 ( 0 1 ) 0 0 4 0 7 - 1 D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 138 artifact waveform during data recording, but this can be eliminated by avoiding amplifier saturation (Harding, 1991; Erfanian et al., 1998). The stimulus artifact has been modelled by Scott et al. (1997) as the superposition of three components. The first is the voltage gradient that appears across the recording electrodes resulting from the stimulus current travelling through the limb. The second component is due to imperfect stimulus isolation that gives rise to a stray capacitance between the stimulating electrodes and ground, which results in a second current that once again creates a voltage gradient at the recording electrodes. The third component is due to electromagnetic coupling between the stimulating and recording leads. This component’s contribution is highly dependent on the impedance of the recording electrodes, quality of the shielding on the leads and their position in space. 2. Artifact removal An analysis of the literature identified many approaches for the removal of stimulation artifact from muscle (EMG), nerve (ENG) and cerebral (EEG) potentials evoked by electrical stimulation. Since EMG/ ENG/EEG are all fundamentally electrophysiological signals, a technique developed to remove stimulus artifact contamination from any of the biopotential recordings, may be modified and used to remove artifact from the other types. These techniques may reduce the effect of stimulus artifact and improve the fidelity of the recorded m-wave. However, most techniques suffer from an inability to adapt to the dynamic nature of stimulation artifact, due to the non-linearities of the stimulation procedure and hence suffer residual artifact. The total removal of the stimulus artifact is necessary for accurate interpretation of the m-wave (Parsa et al., 1998). A brief review of the literature follows. 2.1. Hardware techniques 2.1.1. Blanking A popular method for stimulus artifact suppression is hardware blanking (Roby and Lettich, 1975 (EEG); Knaflitz and Merletti, 1988 (EMG)). One variation of this method is the sample and hold design. These circuits sample the input signal and switch to the hold mode during the artifact period (Freeman, 1971 (EEG); Babb et al., 1978 (EEG)). Hardware-based blanking circuits are usually triggered by an external synchronous pulse from the stimulator or as proposed by Minzly et al. (1993) (EMG), they can be triggered from the stimulus pulse itself. A major disadvantage of the hardware blanking technologies developed is that the blanking time interval is usually fixed by a potentiometer. This may lead to clipping or blanking out of subsequent m-waves if the blanking interval is set too long or if the stimulation parameters (frequency/pulse width/amplitude) change. The approach also fails to take into account the dynamic effect of stimulation whereby the tail of the stimulus artifact may survive the blanking pulse (if set too short) and be recorded along with the m-wave. 2.1.2. Stimulator output stage A combination of the two types of stimulator output stages was proposed by Pozo and Delgado (1978) (EEG). It combined the clinical consistency (as the current delivered is independent of the impedance of the load) of a constant current output stage during stimulation with the low impedance advantage of a constant voltage output stage between stimulus. This had the effect of minimising stimuli artifact transients. 2.1.3. Filtering Analogue filtering was used by Solomonow et al. (1985) (EMG) who implemented an eighth order Chebyshev low pass filter at 550 Hz. While successful in eliminating high frequency components of the artifact, the method allows low frequency components of the artifact to be passed. This predicament was observed by Winchman (2000) (EEG) who noted that in the frequency domain, it is very difficult to remove the stimulus artifact using conventional filters, as there exists a significant overlap between the spectral components of the neuronal signal and the artifact. Fig. 1. Contaminated data (stimulus artifact + m-wave). 2.1.4. Amplifier gain Another artifact removal method was suggested by Roskar and Roskar (1983) (EMG) who used a digitally controlled amplifier gain to suppress the stimulus arti- D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 fact signal. A gain of ×1 was used during stimuli changing to a gain of × 1000 in between stimuli. However, the authors discussed only qualitative results and it has been suggested that a gain ratio of 1000 may not always be sufficient to remove the stimulation artifact (Knaflitz and Merletti, 1988) (EMG). A complete stimulation detection system encompassing many hardware design improvements (including slew rate limiting and windowing) and good experimental technique was proposed by Knaflitz and Merletti (1988) (EMG). Using the system, the authors were able to achieve stimulus artifact levels lower than the ambient noise level. The main problem with any of the hardware approaches described is the inability of the methods to dynamically adapt to changes in stimulus artifact shape. 2.2. Software techniques Following digitisation and storage on a PC, the possibility of artifact removal during post-processing of the data exists (Hines et al., 1996 (EMG)). McGill et al. (1982) (ENG) outlined a straightforward software technique to remove the stimulus artifact. The principle involved acquiring an estimate of the stimulus artifact waveform and subtracting this from the contaminated signal. Three methods of recording an uncontaminated stimulation artifact waveform were outlined: (1) Sub-threshold stimulation: This is where the stimulus intensity is reduced below the threshold for nerve excitation. (2) Recording off ner6e: This method uses a second pair of recording electrodes positioned away from the nerve under examination to record a purely artifactual signal. (3) Double stimulus method: This is where a second stimulus pulse is applied to the nerve during its refractory period. During this refractory period the stimulus fails to evoke a nerve response allowing the recording of the artifact signal. Once an estimated stimulation artifact signal was acquired, it was subtracted from the recorded m-wave with artifact contamination, leaving an estimated uncontaminated m-wave (McGill et al., 1982). Kiss and Shizgal (1989) (EEG) used the digital subtraction method to remove stimulation artifact from recorded compound action potentials. They were able to remove most of the stimulation artifact but acknowledged that the method rarely removes the artifact entirely. They also pointed out that the subtraction method of artifact removal degrades the signal-to-noise ratio of the data. Blogg and Reid (1990) (EMG) recorded myoelectric signals and digitised the data using a 12-bit ADC with 10 kHz sampling. The method 139 involved recording a sub-threshold artifact as a template and also recording the normal contaminated action potentials. Using linear interpolation, amplitude scaling and time synchronisation, the stimulus artifact was removed by subtraction. However, Blogg and Reid (1990) reported that their synchronisation with the stimulus pulse spike was poor (Merletti et al., 1992). The subtraction method of artifact removal suffers from residual artifact remaining at the end of processing. This can be attributed to the fact that the ‘artifact template’ that is subtracted from the contaminated signal is taken usually once at the beginning of the experiment and thus does not take into account the time varying nature of the stimulus artifact and non-linearities present in stimulus artifact generation and recording (Stephens, 1963; McGill et al., 1982). Estimates of the average stimulus artifact waveform was investigated by Winchman (2000) (EEG) who used digital averaging techniques to create a more representative stimulus artifact template. However, even though the method is significantly better in constructing a more valid stimulus artifact, it is acknowledged by Winchman (2000) that the method depends on the assumption that the shape of the stimulus artifact remains the same throughout repeated stimulation. A solution to the problem of the non-linearity in the stimulus component was proposed by Parsa et al. (1998) (ENG). Again the method involved recording either a sub-threshold or dual recording of an uncontaminated stimulus artifact signal and subtracting this from the contaminated m-wave. By using Volterra series expansion, they were able to model the non-linearities of the recorded signal and by using two different non-linear adaptive filter techniques. They were able to achieve better results in artifact suppression than other techniques that took a single sample of the stimulus artifact shape and used this waveform for all subsequent processing even though their are non-linearities in stimulus artifact generation (Stephens, 1963; McGill et al., 1982). Harding (1991) (EEG) proposed another method of artifact removal using artifact peak detection and mathematical equation fitting of the artifact waveform. The method relies upon several assumptions about the artifacts and physiological signal. Again it is acknowledged that residual artifact remains in the data as the mathematical equations do not fit the data perfectly. The correct operation of the method also depends on a noise free data matrix, which is not always possible in experimental situations. Any attempt to use hardware or software blanking techniques on electrophysiological signals contaminated with stimulus artifact depends on the assumption that the stimulus artifact and the biopotential are not overlapping. With short distances between the recording site and the stimulation source or pulse width modulation 140 D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 involving long pulses the artifact and the biopotential will overlap and another approach is needed (Harding, 1991 (EEG); Erfanian et al., 1998 (EMG)). This paper proposes a new approach for the dynamic removal or stimulus artifact based on a fundamental characteristic of the recorded signal. When recording an m-wave, the recorded artifact signal is usually one to two orders of magnitude greater than the pure m-wave (Knaflitz and Merletti, 1988). The method also assumes that the m-wave and artifact are non-overlapping (as discussed) which is true if the latency of the evoked response from the stimulus pulse is sufficiently long (Harding, 1991 (EEG)). Using a two-stage peak detection algorithm, the data matrix is scanned until a peak is detected and using two levels of amplitude threshold, the entire stimulus artifact is removed leaving the uncontaminated m-wave remaining. 3. Method 3.1. Algorithm The technique developed for stimulus artifact removal is a software-based solution. The artifact removal program was written in MATLAB (Mathworks, Nantick, MA). The program removes the stimulation artifact, by setting high (HT) and low (LT) threshold values (Fig. 1) to identify, isolate and remove the stimulus artifact, while leaving the m-wave intact. The algorithm removes the total artifact including both positive and negative spikes and any exponentially decaying tail (Fig. 2). The solution is flexible enough to work for any file size and for any type of recorded stimulus contaminated electroneurophysiologic data. 3.2. Program operation The program was designed to scan for negative as well as positive stimulation artifacts, which it does by considering the absolute magnitude of the data points. The program control flow is as follows: (1) The recorded contaminated (stimulus artifact+ m-wave) data is inputted to the program. (2) The program initially calculates and removes any offset in the recorded signal. It then scans through the absolute data matrix of the artifact-contaminated signal and calculates the maximum value in the array. This value corresponds to the peak artifact amplitude. Then the program initially sets two threshold values: a high threshold (HT) which corresponds to the maximum peak detected divided by two and a low threshold (LT) set as 1/20 times the maximum peak value (Fig. 2). By using the absolute matrix both positive and negative polarities are processed with the same HT/LT values. The program will remove both single and multiphasic artifact waveform, as it removes each artifact as it encounters it. (3) The program then scans the matrix until it reaches an amplitude value that passes the LT level in an increasing direction. As this could be the beginning of a stimulation artifact peak, the program marks the initial LT index point. The program then monitors the data to establish if the amplitude continues to increase and pass the HT value. However, if after passing the initial LT value, the data decreases and passes the LT value again, then it is not an artifact and is either an m-wave or sporadic noise, therefore, the program will ignore it and continue scanning the matrix for artifacts (right-hand loop of flow diagram— Fig. 2). (4) Alternatively, if after passing the initial LT value, the data series amplitude continues to increase and passes the HT value, then the program marks this sequence (which started at the passing of the initial LT value) as a valid stimulation artifact detect. The program continues to monitor the progress of the data noting when it passes the HT (decreasing) and then the LT (decreasing). The program then marks and records the length of the artifact array sub-set (from the matrix index of the initial LT crossing (− 0.1 ms) to the matrix index of the final LT (+ 0.1 ms) crossing with a valid peak detect condition in-between). The program then replaces this stimulation artifact sub-set with zeros (or pre-artifact baseline). 0.1 ms was chosen on either side of the artifact deletion window (LT2–LT1) as it is one sample period (10 kHz sampling) and is necessary to ensure proper functioning of the programs nested loops (left-hand loop of flow diagram— Fig. 2). It is important to note that if the index markers from the first LT to the first HT were replaced with zeros, then only the stimulation artifact spike would be removed. However, it is also necessary to remove any exponential decay of the artifact signal. Therefore, the program continues scanning the matrix and monitors the progress of the data series until the stimulation artifact amplitude drops back to below both the HT and the LT levels (Fig. 1). (5) When developing the technique for batch processing of multiple files, a method of checking the effectiveness of artifact removal was included (Step 5 of flow diagram— Fig. 2). M-wave data files from recordings were given coded filenames e.g. CB10H100. ‘CB’ signifies the subject’s initials, ‘10H’ signifies the stimulation frequency (10 Hz) and ‘100’ signifies the stimulation pulse width. The stimulation was applied for 10 s with a duty cycle of 2:3 and the type of stimulation waveform was asymmetric biphasic. Following visual inspection of multiple artifact files, it was observed that the recorded stimulation artifact typically had three (repolarising factor) spikes for every stimulation artifact (due to repolarising effects). Using this empirically derived information a formula was devel- D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 141 Fig. 2. Algorithm flow diagram. oped to find the approximate number of stimulation artifacts in any recorded file. The formula developed to predict the number of stimulation artifact peaks (SAPP) is: SAPP =(A)×(B)× (C) × D , E (1) where A is the duty cycle on time; B is the stimulation frequency; C, repolarising factor (dependent on stimulation waveform type); D, data recording time (multiples of 5 s); and E, sum of duty cycle on and off period. Using the above example for 10 s of recorded data, the program would expect 2×10 ×3 ×2 = 120 stimulation artifact peaks (40 stimulation artifacts). Since the predicted number of artifact peaks is not an absolute, if the number of artifacts detected was within 5% of that expected using Eq. (1), then the artifact detection process was deemed successful. The 5% tolerance was developed empirically, after examining the output of the recorded data files whose number of artifacts varied from the formula predicted result by less than or equal to 5%. When the algorithm loads the data file into memory it strips the filename to extract the required information. Using this predicted value for the number of peaks in the data matrix, the program compared this figure with the number of artifact pulses it had isolated. If the number of stimulation artifacts detected is outside of this 5% tolerance, then the program automati- D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 142 cally changes the values of the HT and LT appropriately and scans the matrix again, performing accuracy iterations as follows: If the number of artifact pulses removed is too high ( \ 5% of the predicted value), the program increments (by 1%) the HT/LT values and re-runs the algorithm, it continues to increase these threshold values if the number of artifact pulses removed is still too high. Reciprocally if the number of artifact pulses removed is too low ( \ 5% of the predicted value) the program decrements (by 1%) the HT/LT value until the predicted value of stimulus pulses matches the actual value of stimulus pulses identified. The program changes the value of the HT and the LT by varying the denominator value of the equations: High threshold= Low threshold= Peak amplitude , X Peak amplitude , Y where X is initially set as 2, but varies according to feedback iterations; Y is initially set as 20, but varies according to feedback iterations. It continues to do this iteratively until the number of expected artifact waveforms (within 5%) match the number of artifact waveforms removed. To avoid endless program loops and potential loss of m-wave data, the program stops the iterations before the expected number of artifact peaks (within 5% tolerance)=number of artifact peaks removed depending on two factors: (1) The program allows a maximum of 20 accuracy feedback iterations. Most data files find the predicted number of artifacts (within 5%) in less than 10 iterations. (2) It is also important that the program does not keep lowering its thresholds, potentially removing mwaves, for the sake of meeting the predicted target of stimulation peaks. Therefore as an error control, the program calculates the average maximum of the clean m-waves and never allows the HT value to drop below this amplitude. This safeguards the important m-wave data from closed loop feedback iterations, while max- imising the efficiency of the program to remove the artifact pulses. Having safeguards built into the program code allows for batch processing of multiple files without the need to check each individual file. The program automatically generates output graphs and also generates an operation log file (Fig. 3), both of which give the user feedback information on the programs operation (Note: lo – th= low threshold; hi – th= high threshold). In Fig. 3, the program output file shows that it expected 40 (9 , less than, or equal to 5%) stimulation artifact waveforms. Therefore, it would accept 38–42 artifacts detected as a valid result. After setting up the high and low thresholds with initial conditions, the first iteration found 26 stimulation artifact waveforms. Over the next few iterations, the program continued to lower its threshold values until, iteration four, when it found all 40 of the 40 stimulation artifact waveforms. It is important to note that the program will always try to achieve 40/40 artifacts removed, but will accept a result within 5% of predicted. However, this does not mean that the program reaches 5% of the predicted value and stops looking, it always tries to find the maximum number of artifact peaks without breaking the error control rules outlined above. 4. Data collection As discussed, several techniques exist to minimise the effect of stimulus artifact contamination during collection of m-wave data (McGill et al., 1982; Scott et al., 1997; Erfanian et al., 1998). These techniques were incorporated into the experimental design. After the researchers received ethical approval, ten subjects provided informed consent to participate in a study to test the effectiveness of the detection algorithm. The subjects were electrically stimulated at the common peroneal nerve to elicit tibialis anterior contraction. The subjects were seated in a CON-TREX MJ machine; a rotary biomechanical test and training system (CONTREX, CMV-AG Zurich, Switzerland) in order to measure the force produced from the contraction of the tibialis anterior, for future m-wave-torque research. Fig. 3. Output of program process log file. D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 A commercial programmable stimulator (BMR NeuroTech Inc., 1995, Galway, Ireland) was used to provide stimulation pulses to two commercial 32 mm diameter woven conductive cloth stimulation electrodes (Nidd Valley ACUPAD, Yorkshire, England). Strategic placement of the stimulation electrodes with respect to the recording electrodes is critical in minimising the stimulus artifact and obtaining a good signal (Erfanian et al., 1998). The area to be stimulated was clipped (not shaved) of hairs if necessary to ensure a better surface contact. Stimulation electrodes were positioned to elicit good dorsiflexion at 35 Hz 300 ms 50 mA. The stimulating electrodes were placed over the common peroneal nerve (1 cm below head of fibula) and the tibialis anterior muscle. A constant voltage stimulator was used to ensure the artifact transients were relatively short (Knaflitz and Merletti, 1988). An asymmetric biphasic stimulation waveform was used as a biphasic waveform accelerates the discharge of tissue and electrodes capacitance’s through the stimulator output stage (Spencer, 1981). During the first phase the stimulation, current rises rapidly to a positive peak and then reduces in a smooth exponential fall towards zero. In the second phase, the current reverses direction and slowly reduces from a negative peak towards zero again. Overall the net current flow is approximately zero, since the charge transferred in each phase is equal but opposite. EMG recording electrodes were positioned on the midline of the muscle belly 6 cm distally from the stimulation electrodes (McGill et al., 1982). The limb was grounded between the stimulating and recording sites to reduce 50 Hz interference, to hold the mean voltage of the limb near ground and to prevent transthoracic current flow if there is a fault in the stimulator (McGill et al., 1982). The EMG interelectrode spacing chosen was 20 mm, with an electrode diameter of 5 mm. The electrodes were fixed in a pre-amplifier unit with dimensions of 30 mm× 20 mm × 6 mm. The Ag – AgCl electrodes protrude 0.5 mm from the unit. Good electrical contact was achieved between the recording amplifier and the muscle under investigation by shaving the recording site and by mildly abrading and cleaning the skin. Electrode gel was also used to aid electrical conductivity and to minimise skin impedance variation effects (McGill et al., 1982). The electrodes were fixed to the limb using Velcro straps to minimise motion artifact. The EMG amplifier (Jim Clark Ltd., Newcastle, England) incorporated several features to make the device less sensitive to stimulus artifact. The amplifier chosen had a large input impedance (\10 MV). This allows the amplifier to operate independently of changes in the skin impedance. Since there is a large stimulation common mode artifact and power line interference, it was important for the amplifier to have a high (\ 100 dB) 143 common mode rejection ratio (deLuca, 1997). The amplifier was internally clamped with diodes to protect it from damage due to the presence of stimulus artifact and it also had a fast settling time so it could recover quickly from saturation. The amplifier gain was set to 1000 for the experiment. The m-wave data was recorded with a MACLAB (AD Instruments Ltd., CA) data acquisition card. It was necessary to ensure that the full artifact signal was digitised, so the signal was initially sampled at 40 kHz. Spectral analysis of the data showed that the m-wave plus artifact signal had no significant spectral components above 4 kHz (Winchman, 2000). Therefore, a lower sampling rate could be chosen to ease processing overhead and data file size while still maintaining signal integrity. Subsequently data were sampled at 10 kHz, with an anti-alias filter at 5 kHz. Ten subjects were stimulated at three different stimulation frequencies (10, 20 and 30 Hz) and seven different pulse widths (100, 150, 200, 250, 300, 350 and 400 ms). This generated 210 data files with a wide variety of recorded data. 5. Results Rigorous testing of the program algorithm was carried out using the collected experimental data. 5.1. Manual testing If the program algorithm processes a single data file, the user can change the threshold levels manually using visual feedback of the results to achieve 100% stimulation artifact removal. However, in situations where the user visual feedback is removed (e.g. batch processing of multiple files), the program uses Eq. (1) to predict an approximate number of stimulation artifacts to be removed. To assess the effectiveness using this method in batch processing multiple files, a comparison was made of the number of artifacts removed by the program versus the number of artifacts expected (as determined by Eq. (1)). As the predicted number of artifacts present is not exact, a 5% tolerance figure was applied to this number and accepted as a valid result. Several files were processed with the program and then the output data file was compared with the process log file. In all cases the program found the predicted number of artifacts (within 5% tolerance). 5.2. Batch processing Once the accuracy of the formula feedback technique was established, 210 data files were batch processed. The program successfully removed all of the stimulation artifact waveform from all 210 batch processed files. An example of the stimulation artifact removal 144 D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 Fig. 4. (A, B) Waveform stimulated at 10 Hz, pulsewidth = 200 ms. (C, D) waveform stimulated at 30 Hz, pulsewidth =350 ms. program output can be seen in Fig. 4. Fig. 4((A) and (C)) shows a stimulation artifact-contaminated m-wave and Fig. 4((B) and (D)) shows both the contaminated wave in more detail and the subsequent cleaned wave after processing. The program will always try to find the exact predicted number of artifact waveforms, but if after trying a pre-set number of iterations and/or threshold violation conditions, it will accept a value of within 5% that was encountered in the processing. In some situations 0– 5% greater than the predicted number of artifacts are removed. This is due to the limitations of the prediction formula (Eq. (1)). In the formula of Eq. (1), the repolarising factor is equal to three spikes (on average), however, in some of the recorded data files, stimulation artifacts have a combination of four and three spikes. This causes a greater number of artifacts to be present compared to what is predicted. The program tolerates this inaccuracy in the predication model by allowing 101–105 peaks (5%) of a predicted 100, to produce a successful result. 6. Discussion The developed MATLAB (Mathworks) program eliminates stimulus artifact from contaminated m-waves. Unlike other artifact removal approaches, the technique removes both the stimulus artifact spike and the decaying exponential by requiring the data to pass two threshold points (LT and HT) on the rising edge and two threshold points (HT and LT) on the falling edge. The main advantage of the technique is that by using a two-stage threshold approach, the technique can dynamically adapt to different stimulation artifact waveforms. When the experimental data was analysed the D.T. O’Keeffe et al. / Journal of Neuroscience Methods 109 (2001) 137–145 maximum artifact duration was found to be 1.9 ms and the minimum artifact duration was 0.9 ms. The mean artifact duration was 1.3 ms with a standard deviation of 0.25 ms, which is an artifact duration variation of 20%. For the technique to work properly it is important that the m-wave and the artifact signal do not overlap, as the program would remove the artifact from the initial LT up to the final LT, which may include part of the m-wave signal. The residual artifact remaining after removal is negligible, as invariably the LT value is set (dynamically or manually) to just above pre-artifact baseline level to avoid continuous triggering of the algorithm by system noise and to ensure that the maximum amount of contamination is removed. The user is not required to record any pure artifact signals for use in post-processing manipulation methods, such as subtraction. The method is also independent of the variation in artifact shape and duration between stimulation pulses due to non-linearities, as the program removes each artifact it encounters in the data file. The stimulus artifact waveform is replaced with zeros, which makes this technique useful for trials studying small signal amplitudes contaminated with stimulus artifact (residual stimulus artifactB10 mV; Hines et al., 1996). The program allows batch processing of multiple files, using feedback controlled threshold correction based on a developed formula that predicts the number of stimulation artifacts present. It is, however, acknowledged that the formula was developed empirically from the data collected in this experiment and may have to be modified when used as the feedback control mechanism in the processing of other types of data. The program was initially developed using MATLAB (Mathworks), however, when batch processing was implemented, it was observed that data processing took longer than expected. Therefore, the program was converted to C code (Borland Inc., Scots Valley, CA) and compiled as a standalone executable file. This greatly reduced processing time compared to the command line interpretation processing of the MATLAB approach (18 times faster, on the same operating system and computer platform). The technique removed 100% of stimulation artifact waveforms when tested with experimental data, taken from ten subjects whose tibialis anterior was electrically stimulated with various stimulation waveform parameters. At the end of batch processing, the computer program produces a log file, which summarises the program operation on each data file. Using this output file, with automatically generated graphs, the user can ensure that the program is working properly. The software algorithm developed is proposed as a useful tool, in the removal of stimulation artifact waveforms from contaminated electroneurophysiologic data. 145 Acknowledgements The authors would like to acknowledge the support of the Irish Mid-Western Health Board in funding this research. References Babb TL, Mariani E, Strain GM, Lieb JP, Soper HV, Crandall PH. A sample and hold amplifier system for stimulus artifact suppression. Electroenceph Clin Neurophys 1978;44:528 – 31. Blogg T, Reid WD. A digital technique for stimulus artefact reduction. Electroenceph Clin Neurophys 1990;76:557 – 61. BMR NeuroTech Inc. BMR NeuroTech NT2000 operators manual, 1995. deLuca CD. The use of surface electromyography in biomechanics. J Appl Biomech 1997;13:135 – 63. Erfanian A, Chizeck HJ, Hashemi RM. Using evoked EMG as a synthetic force sensor of isometric electrically stimulated muscle. IEEE Trans Biomed Eng 1998;45(2):188 – 202. Freeman JA. An electronic stimulus artifact suppressor. Electroenceph Clin Neurophys 1971;31:170 – 2. Harding GW. A method for eliminating the stimulus artifact from digital recordings of the direct cortical response. Comp Biomed Res 1991;24:183 – 95. Hines AE, Crago PE, Chapman GJ, Billian C. Stimulus artifact removal in EMG from muscles adjacent to stimulated muscles. J Neurosci Meth 1996;64:55 – 62. Kiss I, Shizgal P. Improved artifact rejection and isolation of compound action potentials by means of digital subtraction. J Neurosci Meth 1989;30:219 – 29. Knaflitz M, Merletti R. Suppression of stimulus artifacts from myoelectric-evoked potential recordings. IEEE Trans Biomed Eng 1988;35(9):758 – 63. McGill KC, Cummins KL, Dorfman LJ, Berlizot BB, Luetkemeyer K, Nishmura DG, et al. On the nature and elimination of stimulus artifact in nerve signals evoked and recorded using surface electrodes. IEEE Trans Biomed Eng 1982;29(2):129 – 35. Merletti R, Knaflitz M, DeLuca CJ. Electrically evoked myoelectric signals. Crit Rev Biomed Eng 1992;19(4):293 – 340. Minzly J, Mizrahi J, Hakim N, Liberson A. Stimulus artefact suppressor for EMG recording during FES by a constant current stimulator. Med Biol Eng Comp 1993;31:72 –5. Parsa V, Parker P, Scott R. Convergence characteristics of two algorithms in non-linear stimulus artefact cancellation for electrically evoked potential enhancement. Med Biol Eng Comp 1998;36:202 – 14. Pozo FD, Delgado JMR. Hybrid stimulator for chronic experiments. IEEE Trans Biomed Eng 1978;25(1):92 – 5. Roby RJ, Lettich E. A simplified circuit for stimulus artefact suppression. Electroenceph Clin Neurophys 1975;39:85 – 7. Roskar E, Roskar A. Microcomputer based electromyographic recording system with stimulus artefact suppression. In: Third Medical Conference on Biomedical Engineering, 1983. Yugoslavia: Portoroz. Scott RN, McLean L, Parker PA. Stimulus artefact in somatosensory evoked potential measurement. Med Biol Eng Comp 1997;35: 211 – 5. Solomonow M, Baratta R, Miwa T, Shoji H, D’Ambrosia R. A technique for recording the EMG of electrically stimulated skeletal muscle. J Orthoped 1985;8(4):492 – 5. Spencer HJ. An automatic, optically isolated, biphasic constant current stimulator adaptor for artefact suppression. Electroenceph Clin Neurophys 1981;51:215 – 7. Stephens WGS. The current – voltage relationship in human skin. Med Elec Biol Eng 1963;1:389 – 99. Winchman T. A digital averaging method for the removal of stimulus artifacts in neurophysiologic experiments. J Neurosci Meth 2000;98:57 – 62.