An electronic compass system includes a magnetic sensor circuit having at least
two sensing elements for sensing perpendicular components of the Earth's magnetic
field vector. A processing circuit is coupled to the sensor circuit to filter,
process, and compute a heading. The processing circuit further selects an approximating
geometric pattern, such as a sphere, ellipsoid, ellipse, or circle, determines
an error metric of the data points relative to the approximating pattern, adjusts
the pattern to minimize the error, thereby obtaining a best fit pattern. The best
fit pattern is then used to calculate the heading for each successive sensor reading
provided that the noise level is not noisy and until a new best fit pattern is
identified. The electronic compass system is particularly well suited for implementation
in a vehicle rearview mirror assembly.