Closed-Loop Control of Functional Electrical Stimulation Using a Selectively Recording and Bidirectional Nerve Cuff Interface

Discriminating recorded afferent neural information can provide sensory feedback for closed-loop control of functional electrical stimulation, which restores movement to paralyzed limbs. Previous work achieved state-of-the-art off-line classification of electrical activity in different neural pathways recorded by a multi-contact nerve cuff electrode, by applying deep learning to spatiotemporal neural patterns. The objective of this study was to demonstrate the feasibility of this approach in the context of closed-loop stimulation. Acute in vivo experiments were conducted on 11 Long Evans rats to demonstrate closed-loop stimulation. A 64-channel ( $8\times8$ ) nerve cuff electrode was implanted on each rat’s sciatic nerve for recording and stimulation. A convolutional neural network (CNN) was trained with spatiotemporal signal recordings associated with 3 different states of the hindpaw (dorsiflexion, plantarflexion, and pricking of the heel). After training, firing rates were reconstructed from the classifier outputs for each of the three target classes. A rule-based closed-loop controller was implemented to produce ankle movement trajectories using neural stimulation, based on the classified nerve recordings. Closed-loop stimulation was successfully demonstrated in 6 subjects. The number of successful movement sequence trials per subject ranged from 1–17 and number of correct state transitions per trial ranged from 3-53. This work demonstrates that a CNN applied to multi-contact nerve cuff recordings can be used for closed-loop control of functional electrical stimulation.


I. INTRODUCTION
S PINAL cord injury can disrupt communication between the central nervous system and the periphery, resulting in impairment of movements previously enabled by nuanced supraspinal motor control signals.The restoration of motor function in paralyzed limbs can be achieved using functional electrical stimulation (FES), which triggers desired muscle contractions through patterned stimulation applied to motor axons.Replicating the sophistication of motor commands generated by the CNS using pre-programmed open-loop FES is challenging.This form of FES delivery typically yields limb movement that lacks nuance and the ability to react to unexpected perturbations or errors, and can entail excessive muscle fatigue [1].These shortcomings can be addressed by closedloop FES, which uses sensor feedback to guide stimulation delivery parameters such as stimulation timing, target location, frequency, and intensity.Afferent neural information is an appealing avenue for extracting sensory feedback for closedloop FES, because it avoids the need for external sensors and directly encodes proprioceptive and sensory information used for motor control.
Peripheral nerve interfaces can be used to record afferent signals and extract proprioceptive and sensory information.Closed-loop FES using afferent nerve signals as feedback has been demonstrated in both animal and human trials.For example, Bruns et al. and Holinski et al. both demonstrated FES for cat leg motion control using activity recorded in the dorsal root ganglion (DRG) and decoded by linear regression and multivariate linear equations, respectively [2], [3].Song et al. [4] demonstrated FES for rabbit ankle motion control using activity recorded in the sciatic nerve and decoded using fast independent component analysis combined with a dynamically driven recurrent neural network.Inmann and Haugland [5] demonstrated hand grasp control in humans using activity recorded from the median nerve decoded by rectification and bin-integration, signal filtering, and delay.
Closed-loop FES in clinical applications should use highly selective recording and stimulation techniques and be implemented on devices that are as minimally invasive as possible.Interfacing with multiple individual nerve branches instead of their originating nerve trunk allows for superior selectivity but increases invasiveness due to multiple surgical implants.Similarly, using intraneural or regenerative electrodes allows for superior selectivity compared to extraneural electrodes at the cost of invasiveness [6], [7].Apart from Song et al., each aforementioned study chooses selectivity over minimal invasiveness for one or more of these trade-offs, potentially hindering translation into practice.
Koh et al. demonstrated that a convolutional neural network (CNN) could achieve state-of-the-art accuracy for classifying nerve recordings obtained by multi-contact nerve cuff electrodes.This method was named the Extraneural Spatiotemporal Compound Action Potentials Extraction Network (ESCAPE-NET) [8].Each electrode contained multiple contacts around the circumference of the nerve organized as uniformly separated rings along the length of the nerve to capture spatial and velocity variability between different neural pathways.Individual naturally-evoked compound action potentials (nCAPs) in the sciatic nerve were detected and represented as an image referred to as the spatiotemporal signature, which the CNN was trained to classify.ESCAPE-NET is unique in its focus on classification of individual nCAPs.An advantage of classifying individual nCAPs is to provide high temporal resolution that could potentially handle the scenario of multiple simultaneously active neural pathways.This is because individual nCAPs are less likely to overlap in time than when averaging over longer time windows, as done in other approaches to extraneural data analysis.
The results reported by Koh et al. were based on an off-line analysis of the recorded signals [8], without the presence of stimulation.The objective of this study was to demonstrate that the ESCAPE-NET classification method can be used to provide closed-loop feedback for modulating nerve stimulation.We implement a closed-loop FES system based on a bidirectional, selective peripheral neural interface using a single multi-contact nerve cuff.The novel contribution of this work is to demonstrate that extraneural classification of individual nCAPs is feasible in a closed-loop FES scenario.

II. METHODS
To demonstrate ESCAPE-NET's applicability for closedloop FES, a closed-loop system was designed to produce a movement pattern in response to the selectively monitored afferent activity of several neural pathways.A simple lower limb alternating movement task was selected to validate the system while taking advantage of a well-established experimental model for selective peripheral nerve interfacing, the rat sciatic nerve.

A. Surgical Approach
Acute experiments were conducted on 11 Long-Evans rats (Envigo, Indianapolis, USA).The procedures were approved by the Animal Care Committee of the University Health Network (#6477).Retired male breeders were used due to size requirements for the electrode implantation.Anesthesia was induced through inhalation using isoflurane.The procedure began with an oblique incision along the posterior and dorsal aspect of the hip.Connective tissue was cleared around the incision area to reveal the biceps femoris and gluteus maximus muscles [9], [10], which when separated provide access to the sciatic nerve.The nerve was then gently cleaned of connective tissue using dull instruments, taking care not to damage the nerve.A custom-made planar polyimide electrode was folded over the sciatic nerve proximally to the bifurcation point into the tibial, peroneal and sural nerves, avoiding excessive stretching or scratching of the nerves.The electrode was then fixed in place by stitching through its suture holes.The edges of the wound were pushed closed (not sutured, to allow for adjustments to the instrumentation), covered with a gauze pad, and kept wet with saline.An Ambu Neuroline Monopolar Electromyography needle electrode was placed subcutaneously into the rat's back as a ground.
The extraneural nerve cuff contained an 8 × 8 array of electrode contacts.Figure 1 illustrates the electrode panel design and contact layout.The electrode folds over the nerve along the horizontal axis, bending along the space between the fourth and fifth row of contacts.The electrode dimensions are 20 mm x 8 mm.Contacts are 0.75 mm long along the horizontal axis and 0.25 mm long along the vertical axis.The electrodes were manufactured using commercial fabrication methods (supplied by Safe-PCB Canada Inc.) on a 2-layer polyimide (25 µm thickness) flex printed circuit board with a chemical gold ENIG finish (copper thickness 25 µm, nickel thickness 4 µm, gold thickness 0.05 µm).The reference contact was implemented as a 1 mm x 1 mm contact on the outside of the cuff.

B. Closed-Loop Stimulation
To detect and classify afferent nCAPs using ESCAPE-NET, the closed-loop system sequentially performed the following operations: data acquisition, signal pre-processing (including stimulation artefact removal), nCAP detection, spatiotemporal signature conversion, and ESCAPE-NET classification of spatiotemporal signatures.To use the results of online nCAP classification to modulate stimulation parameters, the system performed the following additional components: neural pathway firing rate monitoring, and a rule-based controller for reactive stimulation.These steps are individually described in the following sections.

C. Detecting and Classifying nCAPs Using ESCAPE-NET
1) Data Acquisition, Signal Pre-Processing, and nCAP Detection: Signals were recorded with a sampling rate of 30 kHz (CerePlex Direct, Blackrock Neurotech, Salt Lake City, UT, USA).The raw signals were processed to detect and represent nCAPs in a consistent format for classification.An nCAP is the summation of action potentials firing synchronously from a group of neurons with similar functional purposes, evoked by naturally occurring phenomena such as changes in limb position or tactile input (as opposed to a CAP evoked by direct electrical stimulation of the nerve).An nCAP corresponds to a detectable "spike" in the nerve cuff electroneurogram (ENG) signal.In this study, an nCAP was classified as tibial branch activity (induced by dorsiflexion of the ankle [11]), peroneal branch activity (induced by plantarflexion of the ankle [11]), or sural branch activity (induced by applying a cutaneous stimulus in the form of pricking to the heel using a Von Frey monofilament [300 g] [12]).Dorsiflexion and plantarflexion of the ankle were administered both manually and through electrical stimulation of the sciatic nerve.Stimulation was delivered (CereStim R96, Blackrock Neurotech, Salt Lake City, UT, USA) to the sciatic nerve from each contact of the nerve cuff, and contact selection was performed manually based on the selectivity and amplitude of movement for both dorsiflexion and plantarflexion.Based on the subject, stimulation sometimes needed to be delivered to multiple contacts simultaneously to induce clear movement.Contact selection was an iterative process as initially effective contacts could lose effectiveness throughout the experiment.Stimulation was delivered in bursts of 30 monopolar biphasic pulses, with amplitude of 215 µA, frequency of 30 Hz, pulse width of 100 µs, and interphase delay of 100 µs.Parameters were chosen to generate smooth movement while providing enough time between pulses to capture nCAPs.
To remove any stimulation artefacts, the recorded signal was zeroed for a portion of time extending from immediately before (0 -1 ms) to after (10 -11 ms) a stimulation pulse.Tripolar referencing was applied to the acquired raw signal, using the average of the contacts in the two outer rings as the reference.Bandpass filtering was then applied using a 4th order Butterworth filter with a 1-3 kHz passband.nCAPs were detected by using the delay-and-add method [13], [14], [15], [16], (applied to the averaged signal of each ring of contacts, centered around either the 4th or 5th ring of contacts, determined empirically) to obtain a superimposed nCAP.The delay-and-add method uses conduction velocity and contact spacing to temporally align nCAPs recorded by longitudinal contacts to obtain a larger superimposed nCAP that is easier to detect.An nCAP was detected anytime the superimposed nCAP signal X crossed a threshold determined by Equation ( 1) [17].To eliminate artefactual data, any nCAP that crossed a threshold of 20 µV was discarded.In this manner, afferent nCAPs were extracted from the intervals between stimulation pulses.Figure 2 shows sample signals through several processing stages.
2) Spatiotemporal Signature: After each detected nCAP was tripole referenced, it was used to create a spatiotemporal signature representation, using 49 time samples before and 50 time samples after the superimposed nCAP's peak, corresponding to 3.33 ms segment centered around the detected spike [8].Note that the delay-and-add operation was used only to detect nCAPs, but the spatiotemporal signatures were extracted from the 64-channel signals.The spatiotemporal signature is an M × T matrix, with M contacts on the electrode and T time samples (here 64 and 100, respectively).The grid of contacts on the electrode was numbered to determine the ordering in the M dimension, as detailed in the "ESCAPE-NET Architecture" section below.Spatiotemporal signatures were used as inputs to the CNN. Figure 3 illustrates sample spatiotemporal signatures.3) ESCAPE-NET Training: ESCAPE-NET was trained using isolated trials of sciatic nerve afferent activity induced by applying dorsiflexion (tibial branch activity) and plantarflexion (peroneal branch activity) to the rat's ankle [11] and applying a cutaneous stimulus to the heel (sural branch activity) using a Von Frey monofilament (300 g) [12].A training dataset unique to each subject was obtained.Dorsiflexion and plantarflexion were induced both manually and through electrical stimulation; pricking of the heel was induced manually.The inclusion of electrically stimulated movement in the training set was motivated by the fact that the nCAPs detected in the closed-loop demonstration are electrically stimulated.Data augmentation was applied to this combined dataset using the methodology described in [8].nerve; the "temporal emphasis" representation orders contacts by length (i.e.every 8 rows of the image belong to a line of contacts running along the nerve), which ensures that rows of pixels are locally related based on contact placement along the length of the nerve.The former exploits the spatial variation of different neural pathways, and the latter exploits the velocity variation of different neural pathways.
For each of the two inputs of the network, there are 3 convolutional layers in sequence that have 32  This version of ESCAPE-NET uses 2,912,963 weights and 150,013,714 floating point operations required for interference on a single input.Possible optimizations of this neural network architecture have recently been investigated to make it appropriate for use in implanted systems [18], [19] however for these in vivo experiments the architecture was kept fixed.

D. Using Online nCAP Classifications to Modulate Stimulation Parameters
All components were implemented online in MATLAB, using the Signal Processing toolbox for pre-processing, the Deep Learning toolbox for Keras NN classification, and Blackrock's MATLAB interfaces cbMEX and StimMex to receive recorded data and control stimulation, respectively.Figure 5 illustrates the devices used for the closed-loop stimulation demonstration and the interactions between them.The experimental setup included a laptop computer equipped with MATLAB which implemented a rule-based controller that directly interacted with the data acquisition system and stimulation device.The data acquisition system and stimulation device were both connected to the surgically implanted custom electrode.The laptop computer had remote access to a desktop computer equipped with a GeForce RTX 3090 GPU for neural network training, allowing for dataset acquisition, neural network training, and closed-loop stimulation to be performed on the same subject within one experiment session.The latency of the closed-loop system was empirically observed to be approximately 3 seconds, which is discussed in more detail in the Discussion section.
1) Neural Pathway Firing Rate Monitoring: The peroneal, tibial and sural branches' firing rates were computed by detecting and classifying nCAPs using ESCAPE-NET within approximately 3-second segments of continuously acquired signal, with 50 samples (1.67 ms) of overlap in between windows to capture any nCAPs that are cut off between windows.For clarification, windows were used so that finite segments of signal could be analyzed in a continuous fashion and firing rates computed -our method classifies individual nCAPs, rather than windows of activity.
2) Rule-Based Controller Design for Closed-Loop Stimulation: Controller design for closed-loop FES is a complex topic, for which a number of sophisticated strategies have been proposed [21], [22], [23], [24].In order to de-couple this complexity from the objective of this experiment, which was to demonstrate classification of individual nCAPs in a closed-loop FES scenario, we designed a simplified control paradigm based on finite state machines (FSMs).The task was designed to minimize controller complexity while requiring two key elements: selective recording from multiple neural pathways, and interleaved recording and stimulation from a single electrode.
Active branches were used to transition between different states of stimulation.Figure 6 illustrates FSMs describing the possible states of stimulation, and which active branch triggered a transition between states.We refer to the FSM depicted in Figure 6a as FSM A. Figure 6b depicts a slightly more sophisticated version of the FSM, which we will refer to as FSM B. Initial focus was placed on demonstrating FSM A, and once it was demonstrated consistently across multiple subjects, both FSMs A and B were attempted.The FSMs were simplified movement tasks selected as an experimental model to reflect a clinically meaningful scenario (monitoring of both joint angles and external stimuli for closed-loop control of FES) while requiring selective neural recording.The desired movement pattern was initiated with a prick of the heel, then oscillating ankle motions was induced via nerve stimulation.In FSM A, oscillation continued until a mistake in monitoring occurred, determined by either tibial or peroneal activity being detected in two consecutive windows.For the FSM A experiments, the highest firing rate within a window was used to identify the active branch (simultaneous activations were not considered).The experiment began in state I, with the foot at rest in a neutral position.No stimulation was administered in state I.If only noise was detected (i.e. the total number of nCAPs was below the noise threshold), state I continued to be held.When a heel prick (sural branch activity) was detected, the state transitioned to state II, which selectively stimulates the nerve to induce dorsiflexion.When dorsiflexion (tibial branch activity) was detected, the state transitioned to state III, which selectively stimulated the nerve to induce plantarflexion.When plantarflexion (peroneal branch activity) was detected, the state transitioned back to state II.
In FSM B, oscillation continued until a second prick of the heel was detected.This required detecting activity in multiple branches simultaneously (both proprioceptive and cutaneous afferents).To detect multiple simultaneously active branches, a firing rate threshold per window was defined for each nerve branch.This was done by analyzing successful trials of FSM A, and choosing a threshold value for each of the three types of neural activity that would yield correct activity detection.

A. Selective Recording During Closed-Loop FES
Closed-loop stimulation was successfully demonstrated in six subjects.Table I reports the number of successful trials achieved for all subjects for which closed-loop stimulation was attempted.A successful trial is defined as one where all 3 neural pathways were correctly identified as active at least for one window each.In other words, each possible transition Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.

TABLE I SUMMARY OF TRIALS ACHIEVED PER SUBJECT. N/A INDICATES THAT
A PROTOCOL WAS NOT ATTEMPTED between states of the FSM should be performed at least once.
For each successful trial, the number of transitions between states was recorded to quantify the robustness of a single trial.The mean and standard deviation for number of state transitions is also reported.Retraining of the network using new smaller datasets occurred between certain trials within a single subject, so the weights of a network used between trials of a subject are not necessarily the same.Also, contact configurations for stimulation delivery often changed over the course of an experiment.Trials of FSM B were not attempted on subjects A-C, and were attempted on subjects D, E and F; trials of FSM B were not achieved for subject E. The CNN classifies each nCAP as either activity from the tibial, peroneal or sural branch.Firing rates were calculated for each branch by summing the number of nCAPs classified as each branch per window.
Figure 7 shows an example of the firing rate trajectories of the three monitored nerve branches within a trial compared to the expected active branch based on the position of the rat's foot and presence of cutaneous stimulus to the heel.In Figure 7a, the highest firing rate per window corresponds to the expected active branch.As dictated by FSM A, detection of sural branch activity begins stimulation delivery, inducing oscillating movements between dorsiflexion and plantarflexion.In Figure 7b, sural branch activity is detected using threshold crossing, whereas tibial and peroneal branch activity remains being detected based on the highest firing rate; by doing so, sural branch activity is monitored separately, and can be used to override stimulation decision-making.As dictated by FSM B, detection of sural branch activity begins stimulation delivery as in FSM A, and a second detection of sural branch activity halts stimulation delivery.One undetected instance of expected sural branch activity occurred at approximately the 26 s mark.Although sural branch activity detection halted stimulation delivery, tibial branch activity was still successfully detected within the same window.The nCAPs detected prior to the start of the trial in Figure 7b correspond to electrical activity that was not intentionally induced, and may for example happen as a result of recording artefacts.To account for this type of event, we disregard results where the number of detected nCAPs is below a certain threshold.Note that the ground truth and detected activity events in Figure 7 are not completely aligned because the window length used to estimate firing rates was longer than the sensory events.Thus, a sensory event may occur after the start of a window but still contribute to the average firing rate reported for that window.The ground truth is based on the timing of stimuli in the video rather than direct information about the nCAPs themselves.Nonetheless, the variations in the relative firing rates demonstrate the responsiveness to these sensory events.
Table II presents the macro F1-score achieved by ESCAPE-NET on the initial datasets acquired off-line from all subjects for which closed-loop FES was attempted.ESCAPE-NET's off-line performance was evaluated using 3-fold cross validation on each subject's dataset collected for NN training.Values ranged between 0.47 ± 0.02 and 0.84 ± 0.01.The table additionally reports the macro-F1 scores corresponding to stimulation-evoked trials alone, to give a more direct indication of the expected performance during the closed-loop experiments.The offline and stimulated results were statistically different (p = 0.0113), suggesting that using training sets that more directly reflect the signals obtained during closed-loop operation may be beneficial in the future.

B. Verification of Stimulation Artefact Removal
To verify that neural signal was detected in between stimulation pulses, the average of the resulting spatiotemporal signatures was analyzed and deemed visually similar to the averaged spatiotemporal signatures of manually induced neural activity.Figure 8 illustrates an example of this comparison.In particular, the peak of the nCAP occurring earlier at one longitudinal end of the nerve cuff compared to the other end was an important visual cue that indicated electrical activity travelling along the nerve.The preprocessing steps for nCAP detection were designed to eliminate pulses with amplitudes higher than the expected range of an nCAP's amplitude.As nCAPs exhibit amplitudes that are significantly lower than electrically evoked CAPs, it is highly improbable that any electrically evoked CAPs due to stimulation were incorrectly detected as nCAPs.For additional confirmation, the nerve was severed distally, and recording was performed while manually moving the subject's foot and stimulating the severed nerve as before.No movement was generated by the stimulation, and no nCAPs were detected for the subject used to generate Figure 8 using the same preprocessing steps, hence the absence of a visual depicting spatiotemporal signatures for nCAPs detected after severing the nerve.

IV. DISCUSSION
This study demonstrated for the first time that classifying individual nCAPs using a CNN can be used to provide feedback information to guide closed-loop electrical stimulation of the nerve.The demonstration was performed in acute in vivo experiments on rats using a single custom-designed nerve cuff electrode and commercial off-the-shelf data acquisition and stimulation devices.

A. Advancements Over Previous Works
Several design choices were made to reduce the invasiveness and increase the number of discriminable neural pathways of our implementation of closed-loop stimulation technology compared to existing approaches.
Previous works demonstrating closed-loop stimulation have used multiple electrodes either to achieve nerve selectivity or to separate recording and stimulation electrodes to diminish stimulation artefacts.Bruns et al. [2] and Holinski et al. [3] both used a microelectrode array for recording; Bruns et al. used 1-3 muscle electrodes per muscle group for stimulation and Holinski et al. used intraspinal wire electrodes for stimulation.This study uses a single nerve cuff electrode capable of simultaneous recording and stimulation.
Using a single nerve cuff electrode yielded complex issues such as signal selectivity, stimulation artefacts, and selective stimulation.This study has achieved recording selectivity and managed stimulation artefacts using signal processing techniques.Minimizing the number of implanted devices in a user reduces the complexity of the required surgical procedure, potentially reducing side effects.Using a single nerve cuff electrode for recording and stimulation also eliminates the need for external sensors (e.g.pressure sensors, accelerometers, position sensors) or muscle stimulators; this is advantageous in the context of reliability, positioning and mounting of external devices [25].Surgically implanted devices have the additional advantage of being externally invisible, a trait that users desire to minimize attention drawn to their condition [26], [27].
Song et al. demonstrated closed-loop FES in rabbits using a single multi-contact nerve cuff electrode on the sciatic nerve for both recording and stimulation [4], discriminating between signals from 2 neural pathways as feedback information.This study discriminates between 3 neural pathways and multiple simultaneously active neural pathways, and classifies individual nCAPs rather than longer time windows.
One of the main advantages of classifying individual nCAPs is the ability to detect multiple simultaneously active neural pathways, which would result in a train of alternating types of nCAPs.Successful trials of FSM B demonstrated the ability to detect activity from two neural pathways happening in temporal proximity.Pricking of the heel was administered approximately when the foot was dorsiflexed or plantarflexed, to induce approximately simultaneous activity in two neural pathways.This work's ability to differentiate between 3 neural pathways and multiple simultaneously active neural pathways shows its potential applicability to complex nerves with more neural pathways.
The CNN used in this demonstration is more suitable for implementation on implantable devices compared to the CNN used in [8].This demonstration used a version of ESCAPE-NET with reduced resource requirements, requiring 7.9x fewer weights and 3.5x fewer floating point operations.This reduced computational complexity places fewer constraints on the size of memory devices and power sources required for hardware implementation of the algorithm.Less demanding hardware requirements facilitates implementation on implantable devices.Further reductions of the neural network size are expected to be possible with additional optimization [18].
Apart from the closed-loop demonstration, this study shows that ESCAPE-NET can yield reasonable performance using a different neural interface and contact configuration than previously reported in [8], as reported in Table II.This finding provides support for the generalizability and reproducibility of the approach.In these experiments, a higher macro F1score did not always correspond to successful closed-loop FES demonstration.Conversely, a low macro F1-score did not always correspond to failed closed-loop FES demonstration.This may be due to robustness issues, further discussed below, related to the time elapsed between initial dataset collection and closed-loop FES demonstration attempts.

B. Limitations and Avenues for Improvement
We encountered robustness issues during this study that should be mitigated or addressed in future studies.These issues resulted in the need to retrain the CNN on newer data, the need to change contacts used for stimulation, unequal amounts of detected nCAPs between the three classes, or occasional failure to achieve closed-loop FES demonstration on particular subjects.Several factors may have contributed to these robustness issues, including nerve damage during the surgical procedure, poor or unstable electrode-tissue interface, inconsistent signal quality and ability to functionally stimulate due to relatively unguided electrode placement, shifting of the electrode position, inconsistent contact coverage around the circumference of the nerve (a region in the middle of the electrode without contacts, and the way the electrode is folded leaves another region without contacts), insufficient moisture leading to drying of the nerve, influence of anesthesia on signal quality, and electrical interference from nearby devices.Increased stability may be achieved through refining nerve cuff designs to ensure a close and stable interface with the nerve at all contacts and to equalize coverage of contacts across the circumference of the nerve, and using more sophisticated stimulation configurations to better control current flow [28].Automated methods for evaluating the best contacts (e.g.highest signal-to-noise ratio or contact information metric [8]) and rejecting contacts obtaining poor signal will improve the overall signal quality.
In practice, a user may periodically recalibrate the CNN by providing updated labeled data to either augment or replace the existing dataset and recalibrate appropriate contacts for stimulation.Studies may be performed to optimize the recalibration process so that it can be quickly and easily performed at home by the user.Sammut et al. simulated natural changes in nerve cuff signals due to connective tissue growth and device rotation, demonstrating that a semi-supervised self learning approach may be used to reduce the frequency of CNN re-training [29].To further reduce recalibration frequency, machine learning methods may be explored to generate new synthetic data based on predicted trends in signal characteristics to be evaluated using the semi-supervised self learning approach.For example, Shi et al., Saxena and Cao, and Wang et al. have developed methods of predicting spatiotemporal data using convolutional long short-term memory networks [30], general adversarial networks [31], and recurrent neural networks [20], respectively.To recalibrate stimulation without using the brute-force approach of testing all contacts individually and in combination, methods of reshaping the nerve to move targeted nerve branches closer to the surface [32] or fascicle localisation to facilitate targeted stimulation [33] could be explored.
Our methods for detecting activity in a particular neural pathway was based on either the majority firing rate detected within a time window, or whether a firing rate had exceeded a certain threshold.As a result, the classifier did not need to perform with particularly high accuracy for the FSM to function as expected.Future work should optimize the confidence of a classifier for each window of nerve activity.The detected firing rate for a neural pathway is a function of both the total number of nCAPs detected and the classification accuracy.For example, in Figure 7, plantarflexion firing rates were higher during dorsiflexion than plantarflexion because the overall number of nCAPs was higher during dorsiflexion.Normalization strategies to compensate for these occurences may be warranted.Manual pricking of the heel using a Von Frey monofilament was difficult to perform in a consistent manner with temporal accuracy, especially while the foot was moving due to nerve stimulation.A structure that can secure the rat limb and apply mechanical pricking of the heel may be able to ensure more consistent manipulation of the subject, similar to what was used by Brunton et al. [34].
A CNN's classification ability is often a result of high computational complexity, which translates to larger devices and more computation time due to higher resource requirements.A CNN optimized for implementation on implantable devices should be designed, with a focus on reducing memory and power requirements, while maintaining reasonable classification accuracy for its intended application [18].This would reduce battery size, hardware form factor and operational latency.Alternatively, a fully implantable neural interfacing device with wireless data communication capabilities could be envisioned, with data processing and stimulation decision-making being performed on another mobile device located outside of the body (or on a cloud platform), and connected in a closed loop with the implanted device [35].
Beyond the efficiency of the CNN itself, the overall system latency in this study was determined by the time needed to read in data from a buffer, process the resulting signal, classify detected nCAPs, and make a corresponding stimulation decision, and was empirically observed to be approximately 3 seconds (as visible in Figure 7).A limitation of the study is that we did not measure the time required for individual operations within this loop.The 3 second buffer duration was appropriate to obtain accurate estimates of firing rates, but the trade-off between accuracy and latency should be further characterized in future work.Another limitation of the study is that we did not consistently document failed attempts.Focus was placed on documenting successful attempts due to the study's goal of demonstrating a proof of concept.

V. CONCLUSION
Our findings demonstrate that extraneural classification of individual nCAPs is feasible in a closed-loop FES scenario.Individual nCAPs detected in multichannel cuff electrode recordings were classified using the ESCAPE-NET CNN, providing fascicular activity levels that determined the type of stimulation to deliver.This method detects multiple neural pathways firing in temporal proximity, showing potential for applicability to nerves with more neural pathways.Design choices made to minimize invasiveness include the use of a single electrode for simultaneous recording and stimulation and use of a modified version of ESCAPE-NET with reduced resource requirements [8].These results constitute an important step towards implementing closed-loop FES in clinical applications.Future work should focus on increasing robustness and conducting chronic implantation studies to support translation to humans.Beyond the ability to restore nuanced motor function in paralyzed limbs, closed-loop neuromodulation technology may be used to integrate sensory feedback into prosthetic limbs and to manage ailments such as chronic pain, diabetes, or incontinence.

Fig. 1 .
Fig. 1. a) Schematic of the electrode's contacts layout.The electrode is folded over the nerve along the horizontal axis.Each column of contacts is pressed against the circumference of the nerve, and the 8 columns are spaced along the length of the nerve.Suturing through the stitching holes (6 blue holes at the top and bottom of the panel) secures the electrode in position.A reference contact is situated on the backside of the depicted surface.b) Photograph of a sample manufactured electrode.

Fig. 3 .
Fig. 3. Sample spatiotemporal signatures collected for each form of manual stimuli (dorsiflexion, plantarflexion and heel-prick).The top row of signatures are formatted for spatial emphasis and the bottom row for temporal emphasis.
Offline training was performed remotely on a desktop computer equipped with a GeForce RTX 3090 GPU during the in vivo experiment.100 trials of each of the 3 types of manual stimuli were initially performed.As the process of data transfer, signal pre-processing, conversion to training dataset, and NN training typically took over an hour, additional training was continually performed on new smaller datasets after the initial training stage.Retraining was performed to adapt the NN to any minor shifts of the electrode's positioning due to hindlimb movements or changes in the recording site's interface with the tissue.Performing additional training on a new smaller dataset was much less time-intensive, typically taking a 5-10 minutes.Across all subjects, up to 6 iterations of retraining were performed.The additional training dataset was comprised of activity induced by electrically stimulated dorsiflexion and plantarflexion, and manual pricking of the heel, without data augmentation.The number of trials for each type of activity during retraining was empirically adjusted to ensure similar numbers of detected nCAPs across all three labels, typically aiming to achieve 100-200 detected nCAPs.4) ESCAPE-NET Architecture: A modified version of ESCAPE-NET [8] was used to classify detected nCAPs as illustrated in Figure 4.The CNN receives two inputs, corresponding to two different representations of the spatiotemporal signature.The two representations differ in the ordering of the contacts.The "spatial emphasis" representation orders contacts by ring (i.e.every 8 rows of the image belong to a ring of contacts), which ensures that rows of pixels are locally related based on contact placement around the circumference of the

Fig. 4 .
Fig. 4. Illustration of a modified version of ESCAPE-NET, the CNN used for classifying spatiotemporal signatures.
filters and use the ReLU activation function.The first convolutional layer has 8 × 8 filters, the second has 4 × 4 filters, and the third has 2 × 2 filters.The convolutional layers are separated by 2 × 2 max pooling layers for data downsampling.To initialize the weights of the first and second convolutional layers, they were temporarily connected to dense layers and trained for 25 epochs.The pair of convolutional layer stacks are concatenated after the third convolutional layer into a dense layer that has 64 neurons and uses the ReLU activation function.Dropout at a rate of 0.5 is used on this dense layer.The final layer is a dense layer responsible for classification into the 3 possible classes.

Fig. 6 .
Fig. 6.Diagram of the FSMs used in the rule-based controllers for closed-loop stimulation.a) Diagram depicting FSM A, which ends when a window of activity is incorrectly classified.b) Diagram depicting FSM B, which ends when a heel prick is detected, or a window of activity is incorrectly classified.

Fig. 7 .
Fig. 7. Comparison between ground truth activity and detected activity for 2 example successful trials.Ground truth activity is manually annotated based on video recordings of each trial, and detected activity is based on saved CNN classification outputs.a) Successful trial of FSM A demonstrated in subject A. b) Successful trial of FSM B demonstrated on subject D. Includes one manually annotated heel prick that was not detected by CNN classification.

Fig. 8 .
Fig.8.Example of averaged spatiotemporal signatures for nCAPs induced manually (left) and via electrical stimulation (right).The peak region is indicated in yellow, and notably occurs earlier on higher numbered contacts.Numbering was performed such that each ring of contacts is grouped together.

TABLE II MACRO
F1-SCORES ACHIEVED BY ESCAPE-NET PER SUBJECT