Step 1: The locomotor movements of the right leg were recorded using the video camera system. In parallel, neural signals were recorded from the microelectrode array implanted into the leg area of the primary motor cortex. The signals were band-pass filtered (0.5-7.5kHz). A threshold was at 3 to 3.5 times the standard deviation in order to obtain spike events. The two data streams were saved onto computers. Step 2: Visual inspection of the video frames allowed the identification of foot off and foot strike gait events. We estimated the spike rates from overlapping 150ms bins that were updated every 20ms. Gait events were then synchronized with the spike rate estimates using a trigger saved with the neural data that marked the onset of video recordings. Step 3: We extracted feature vectors that originated at foot off and foot strike events and assigned them to foot off and foot strike motor state classes, respectively. All other feature vectors were assigned to the neither class. Step 4: Motor state classes of feature vectors were used to calibrate a regularized linear discriminant analysis decoder. Step 5: The decoder was uploaded into our real-time analysis application running on the control computer. Neural data was collected in real-time, processed into spike rate estimates, and passed through the decoder that calculated the probabilities of foot off and foot strike motor states. When one of the motor state probabilities crossed a threshold of 0.8, a command to trigger the flexion or extension hotspot stimulation protocols was sent to the neural research programmer, which relayed this instruction to the implanted pulse generator. Due to the wireless communication, the command was executed 178ms (Q1) or 105ms (Q2-3) after the detection of the motor states.