You sit in a chair, facing a computer screen, while a clinician sticks electrodes to your scalp with a viscous goop that takes days to wash out of your hair. Wires from the sensors connect to a computer programmed to respond to your brain’s activity.

Try to relax and focus. If your brain behaves as desired, you’ll be encouraged with soothing sounds and visual treats, like images of exploding stars or a flowering field. If not, you’ll get silence, a darkening screen and wilting flora.

This is neurofeedback, a kind of biofeedback for the brain, which practitioners say can address a host of neurological ills — among them attention deficit hyperactivity disorder, autism, depression and anxiety — by allowing patients to alter their own brain waves through practice and repetition.

The procedure is controversial, expensive and time-consuming. An average course of treatment, with at least 30 sessions, can cost $3,000 or more, and few health insurers will pay for it. Still, it appears to be growing in popularity.