The low-frequency magnetic field noise resulting from the laboratory power supply is one of the main decoherence sources of trapped-ion qubits. Synchronizing the experimental sequence to the phase of the power line is widely used to mitigate this problem, but it will greatly reduce the experimental efficiency. In this paper, we experimentally demonstrate a simple active compensation method to reduce the observed 50 Hz and 150 Hz strong magnetic noise in an ion trap induced by the power line. In our method, a single 40Ca+ ion is used as the noise probe and an reverse compensation signal is generated by a programmable arbitrary waveform generator (AWG).
After compensation, an 86% reduction of the periodic magnetic field fluctuation and over 35-fold extension of the coherence time from 70 µs to 2500 µs were observed. This method can also be applied to compensate other spectral components of the magnetic field noise related to the power line, and it is also useful for other atomic systems such as neutral atoms.