A device includes a housing, a first magnetic field sensor, a second magnetic field sensor, and a control module. The housing is configured to be implanted in a patient. The first magnetic field sensor is located at a first location within the housing and is configured to measure a first strength of a magnetic field at the first location. The second magnetic field sensor is located at a second location within the housing and is configured to measure a second strength of the magnetic field at the second location. The control module is configured to identify a source of the magnetic field based on the first and second strengths.