A magnetic field sensor, comprising: at least one magnetic field sensing element (14a-14c) configured to generate a magnetic field signal influenced by a ferromagnetic object; peak finding circuitry (20, 54) operable to identify at least one of a positive peak value or a negative peak value of the magnetic field signal; a threshold generation module coupled to receive the at least one of the positive peak value or the negative peak value, wherein the threshold generation module comprises: a peak-to-peak calculation module operable to determine a peak-to-peak value by using the at least one of the positive peak value or the negative peak value; a threshold calculation module (504, 506) operable to determine an upper threshold value and a lower threshold value based on the peak-to-peak value, wherein the upper threshold value is a first predetermined percentage of the peak-to-peak value and the lower threshold value is a second lower predetermined percentage of the peak-to-peak value; and a threshold limiting module operable to identify a difference between the upper threshold value and the lower threshold value, and, if the difference is smaller than a minimum separation value based on a function of an RMS noise level associated with the magnetic field signal, operable to set the difference between the upper threshold value and the lower threshold value to a corrected difference value. at least one magnetic field sensing element (14a-14c) configured to generate a magnetic field signal influenced by a ferromagnetic object; peak finding circuitry (20, 54) operable to identify at least one of a positive peak value or a negative peak value of the magnetic field signal; a threshold generation module coupled to receive the at least one of the positive peak value or the negative peak value, wherein the threshold generation module comprises: a peak-to-peak calculation module operable to determine a peak-to-peak value by using the at least one of the positive peak value or the negative peak value; a threshold calculation module (504, 506) operable to determine an upper threshold value and a lower threshold value based on the peak-to-peak value, wherein the upper threshold value is a first predetermined percentage of the peak-to-peak value and the lower threshold value is a second lower predetermined percentage of the peak-to-peak value; and a threshold limiting module operable to identify a difference between the upper threshold value and the lower threshold value, and, if the difference is smaller than a minimum separation value based on a function of an RMS noise level associated with the magnetic field signal, operable to set the difference between the upper threshold value and the lower threshold value to a corrected difference value. a peak-to-peak calculation module operable to determine a peak-to-peak value by using the at least one of the positive peak value or the negative peak value; a threshold calculation module (504, 506) operable to determine an upper threshold value and a lower threshold value based on the peak-to-peak value, wherein the upper threshold value is a first predetermined percentage of the peak-to-peak value and the lower threshold value is a second lower predetermined percentage of the peak-to-peak value; and a threshold limiting module operable to identify a difference between the upper threshold value and the lower threshold value, and, if the difference is smaller than a minimum separation value based on a function of an RMS noise level associated with the magnetic field signal, operable to set the difference between the upper threshold value and the lower threshold value to a corrected difference value.