Energy is transmitted noninvasively to a patient using electrode-based stimulation devices or magnetic stimulation devices that are designed to non-invasively stimulate nerves selectively. The devices produce impulses that are used to treat atrial fibrillation, by stimulating a vagus nerve of a patient. The devices are also used to forecast the imminent onset of atrial fibrillation and then avert it by stimulating a vagus nerve.