Self calibrating magnetometer