| Algorithm 1. Detecting the onset of muscle activity in the EMG signal |
| Input: x—EMG signal, N—signal length |
| /* Step 1: Determine the area of activity */ |
| 1 Peak ← local maxima detection(x) |
| 2 Cluster ← Separation into 2 groups using EM |
| - muscle activity |
| - background noise |
| 3 PDFactivity ← Kernel Density Estimation (KDE) for muscle activity |
| 4 PDFnoise ← KDE for background noise |
| 5 for n ← 1 to N do |
| 6 if PDFactivity[n] > PDFnoise[n] then |
| 7 activeregion ← n |
| 8 end |
| 9 end |
| 10 onsetrough ← activeregion starting point |
| / Stage 2: Onset clarification / |
| 11 W ← signal window around onsetrough |
| 12 Energy ← Teager–Kaiser energy operator |
| 13 onsetfinal ← the point where energy changes the most |
| 14 return onsetfinal |
| Output: onsetfinal—starting point of muscle activity |