A method is described for processing a waveform signal containing a stimulus artifact and one or more neuronal action potentials. An electrical stimulation signal is derived based on satisfying a cost function comparison with a plurality of known neuronal action potential waveforms.