Bioelectrical signals may be sensed within the brain by two or more electrodes to determine characteristics of a function of the brain. The signals obtained by the electrodes may be plotted over time to determine whether the brain function exhibits a normal or an abnormal pattern. If the brain function exhibits an abnormal pattern, an implantable medical device may dynamically determine based on the abnormal pattern and a previously-obtained plot associated with normal brain function, an appropriate electrical stimulation therapy. Application of the appropriate electrical stimulation therapy causes the brain function to shift from the abnormal pattern to the normal pattern.