A magnetic field sensor comprising: a plurality of magnetic field sensing elements (202a, 202b; 302a, 302b; 322a, 322b) including: a first magnetic field sensing element arranged to have a maximum response to an external magnetic field (106; 516) and a reference magnetic field (425; 514) along a first axis and having an output that provides a first signal representing the magnetic field as detected by the first magnetic field sensing element; and a second magnetic field sensing element arranged to have a maximum response to the external magnetic field (106; 516) and the reference magnetic field (425; 514) along a second axis and having an output that provides a second signal representing the magnetic field as detected by the second magnetic field sensing element; a coil structure (204; 304; 324; 404; 910; 614; 704; 724; 810; 528) configured to generate the reference magnetic field (202a, 202b; 302a, 302b; 322a, 322b) when a current passes through the coil structure (204; 304; 324; 404; 910; 614; 704; 724; 810; 528); a memory (412; 924; 824) containing at least one reference gain value comprising a relative gain between the first and second magnetic field sensing elements; a gain equalization circuit (406; 904; 804; 510) coupled to receive the first signal and the second signal and configured to: extract a first reference portion of the first signal representing the reference field; extract a second reference portion of the second signal representing the reference field; measure a first gain of the first reference portion; measure a second gain of the second reference portion; compare the first gain to the at least one reference gain; compare the second gain to the at least one reference gain; adjust the first gain based on the comparison of the first gain and the reference gain value so that the first gain is normalized to an expected value; and adjust the second gain based on the comparison of the second gain and the reference gain value so that the second gain is normalized to an expected value. a plurality of magnetic field sensing elements (202a, 202b; 302a, 302b; 322a, 322b) including: a first magnetic field sensing element arranged to have a maximum response to an external magnetic field (106; 516) and a reference magnetic field (425; 514) along a first axis and having an output that provides a first signal representing the magnetic field as detected by the first magnetic field sensing element; and a second magnetic field sensing element arranged to have a maximum response to the external magnetic field (106; 516) and the reference magnetic field (425; 514) along a second axis and having an output that provides a second signal representing the magnetic field as detected by the second magnetic field sensing element; a first magnetic field sensing element arranged to have a maximum response to an external magnetic field (106; 516) and a reference magnetic field (425; 514) along a first axis and having an output that provides a first signal representing the magnetic field as detected by the first magnetic field sensing element; and a second magnetic field sensing element arranged to have a maximum response to the external magnetic field (106; 516) and the reference magnetic field (425; 514) along a second axis and having an output that provides a second signal representing the magnetic field as detected by the second magnetic field sensing element; a coil structure (204; 304; 324; 404; 910; 614; 704; 724; 810; 528) configured to generate the reference magnetic field (202a, 202b; 302a, 302b; 322a, 322b) when a current passes through the coil structure (204; 304; 324; 404; 910; 614; 704; 724; 810; 528); a memory (412; 924; 824) containing at least one reference gain value comprising a relative gain between the first and second magnetic field sensing elements; a gain equalization circuit (406; 904; 804; 510) coupled to receive the first signal and the second signal and configured to: extract a first reference portion of the first signal representing the reference field; extract a second reference portion of the second signal representing the reference field; measure a first gain of the first reference portion; measure a second gain of the second reference portion; compare the first gain to the at least one reference gain; compare the second gain to the at least one reference gain; adjust the first gain based on the comparison of the first gain and the reference gain value so that the first gain is normalized to an expected value; and adjust the second gain based on the comparison of the second gain and the reference gain value so that the second gain is normalized to an expected value. extract a first reference portion of the first signal representing the reference field; extract a second reference portion of the second signal representing the reference field; measure a first gain of the first reference portion; measure a second gain of the second reference portion; compare the first gain to the at least one reference gain; compare the second gain to the at least one reference gain; adjust the first gain based on the comparison of the first gain and the reference gain value so that the first gain is normalized to an expected value; and adjust the second gain based on the comparison of the second gain and the reference gain value so that the second gain is normalized to an expected value.