Abstract:
A method includes acquiring magnetic data from a magnetometer, processing the magnetic data to perform robust calibration, and generating optimum calibration parameters using a calibration status indicator. To that end, the method includes generating a calibration status indicator as a function of time elapsed since a last calibration and variation in total magnetic field in previously stored magnetic data, detecting anomalies, and extracting a sparse magnetic data set using comparison between the previously stored magnetic data and the magnetic data. Calibration parameters are generated for the magnetometer using a calibration method as a function of the magnetic data set. The calibration parameters are stored based on performing a validation and stability check on the calibration parameters, and weighted with the previously stored calibration parameters to produce weighted calibration parameters. Calibration settings are generated as a function of the weighted calibration parameters, if the weighted calibration parameters were produced.

Description:
TECHNICAL FIELD 
       [0001]    This disclosure relates to the field of magnetic sensors, and, more particularly, to the calibration of magnetic sensors. 
       BACKGROUND 
       [0002]    Portable electronic devices, such as smartphones, smartwatches, tablets, wearables and the like are increasingly popular in the marketplace. Such devices perform many functions. In the furtherance of the performing of those functions, such devices may contain a variety of sensors such as accelerometers, gyroscope, barometers, and magnetometers. 
         [0003]    Magnetometers may function to detect the magnetic field including the Earth&#39;s magnetic field along its axes. In operation, such magnetometers produce a voltage proportional to the strength and polarity of the Earth&#39;s magnetic field along the axis with which that magnetometer is directed. From this voltage, the intensity of the magnetic field along that axis may be calculated or estimated. 
         [0004]    This magnetic field information may be used for determining the orientation of the electronic device relative to the Earth&#39;s magnetic North, for example, or may be used to determine a change in orientation of the electronic device, or other types of information. Since it is desirable to achieve high accuracy in the determination of heading with respect magnetic North, accurate and precise methods of calibrating such magnetometers (which are affected by multiple factors such as hard iron effect, soft iron effect, and magnetic anomalies) are necessary. 
       SUMMARY 
       [0005]    This summary is provided to introduce a selection of concepts that are further described below in the detailed description. This summary is not intended to identify key or essential features of the claimed subject matter, nor is it intended to be used as an aid in limiting the scope of the claimed subject matter. 
         [0006]    A method disclosed herein includes acquiring magnetic data from a magnetometer, and in a processing device, and method and steps for calibrating magnetometer sensor with high accuracy to output reliable measurements. 
         [0007]    According to further aspects, the calibration process described here can automatically compute the quality of calibration, determine the need for calibration of sensor, and collect required magnetometer data from user normal movement or 8 pattern motion. The process to compute the calibration quality is based on parameters such as time elapsed since the latest successful calibration, the last anomaly detection event, and the absolute variation of total magnetic field. 
         [0008]    The calibration process includes detection of anomaly to prevent computing incorrect calibration parameters. The accuracy of computing calibration parameters with anomaly detection process significantly improves the stability and accuracy of calibration process. 
         [0009]    The calibration method may be ellipsoidal or spheroid fitting. The ellipsoid characterizes the inherent error such as soft iron effect, hard iron effect, and mechanical error (non-orthogonality of axes) in magnetometer sensor. Further, the process isolates the erroneous data by performing a robust ellipsoidal fitting on unique stored magnetometer measurements. The calibration parameters may be generated if calibration status indicator indicates that the time elapsed since a last calibration exceeds a threshold elapsed time and if the calibration status indicator indicates an anomaly in the magnetic data. 
         [0010]    The stored magnetic data, to perform calibration, may be interpreted to minimum data sets reduced in dimension to perform stable calibration. The process further can reduce the data sets for memory and computational efficiency. The magnetic data set may be stored such that it has elements that are separated with fixed Euclidian distances with respect to adjacent elements and that were acquired during a given time interval. 
         [0011]    The process of checking whether the magnetic data set is sufficient for the calibration method may include determining a number of unique samples in the magnetic data set, determining a range of the magnetic data set, and determining that the magnetic data set is sufficient if the number of unique samples exceeds a threshold number of unique samples and if the range of each axis exceeds a threshold range for each axis. 
         [0012]    The calibration parameters may also be generated based upon the sanity check indicating that the stored unique magnetic data set is usable for the calibration method. Performing the sanity check on the stored magnetic data set may include eigenvalues comparison of a cross correlation matrix formed from the magnetic data set, and significant motion speed check. 
         [0013]    The calibration parameters may be generated as a set of newly generated calibration parameters. These parameters may be stored as a plurality of sets of previously stored calibration parameters. The consistency check may include comparing the set of newly generated calibration parameters to the plurality of sets of previously stored calibration parameters and discarding a set of calibration parameters which is most inconsistent with other sets of calibration parameters. The new calibration parameters may be stored in the calibration parameter buffer is based on a time difference between generation of the new calibration parameters and the previously stored calibration parameters, and based on a consistency check between the calibration parameters and previously stored calibration parameters and a quality check on the calibration parameters. The calibration parameters and the previously stored calibration parameters are weighted to produce weighted calibration parameters, if the calibration parameters were stored in the calibration parameter store. 
         [0014]    The new calibration parameters and the previously stored calibration parameters may be weighed as a function of quality and a difference between generation thereof and present time. 
         [0015]    The magnetometer may be part of a portable electronic device, and the magnetometer may be operated pursuant to the calibration settings and changing a graphical display of the portable electronic device as a function of the magnetometer. Calibrated magnetic field strength measurements, when used in conjunction with acceleration data, can be used to determine device orientation with respect to magnetic North. The steps described above may be performed in the processing device in under two seconds. It should be appreciated that device counterparts are also within the scope of this disclosure. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0016]      FIG. 1  is a block diagram of a portable electronic device such as may be used with the techniques disclosed herein. 
           [0017]      FIG. 2  is a flowchart of a method of calibrating a magnetic sensor for a portable electronic device. 
           [0018]      FIG. 3  is a flowchart showing individual steps of the sufficiency test of the flowchart of  FIG. 2 . 
           [0019]      FIG. 4  is a flowchart showing individual steps of the sanity check of the flowchart of  FIG. 2 . 
       
    
    
     DETAILED DESCRIPTION 
       [0020]    The present description is made with reference to the accompanying drawings, in which example embodiments are shown. However, many different embodiments may be used, and thus the description should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete. Like numbers refer to like elements throughout. 
         [0021]    Methods and techniques will be described herein for calibrating magnetic sensors, or magnetometers, used in electronic devices. Such a sample electronic device  100  will now be described with reference to  FIG. 1 . The electronic device  100  is portable and may be a smartphone, smartwatch, tablet, or be in another suitable form factor. The electronic device  100  includes a magnetic sensor or magnetometer  102  which produces a voltage proportional to the strength and polarity of the Earth&#39;s magnetic field along the axis with which that magnetometer is directed. A processing device  104 , such as a microprocessor, programmable logic device, field programmable gate array, microcontroller, or system-on-chip is coupled to receive the output from the magnetometer  102 . A display  106  is coupled to the processing device  104  for the purposes of displaying output, and may be touch sensitive for the purposes of receiving input. 
         [0022]    With reference to the flowchart  200  of  FIG. 2 , a method of calibrating the magnetometer  102  is now described. It should be understood that any steps described herein may be performed by the processing device  104  even if not specifically described as such. Magnetic data is acquired by the processing device  104  from the magnetometer  102  (Block  202 ) at regular intervals, such as regular intervals of one second. After each data acquisition, the processing device  104  checks for an anomaly in the data collected either during that acquisition or during a certain time period including the acquisition (Block  204 ). The anomaly checking is performed by looking at the magnitude of the magnetic data, such as by seeing whether the sum of the magnitudes of the elements of the magnetic data exceeds a threshold. If an anomaly is detected, it is undesirable to use that magnetic data, and may even be undesirable to use magnetic data collected for a period prior to the one collected of that magnetic data, so a data buffer or data store storing the magnetic data (and previously collected magnetic data) is erased or deleted (Block  206 ), and then new magnetic data is acquired (back to Block  202 ). 
         [0023]    If no anomaly was found, the magnetic data is checked to determine whether the magnetometer  102  was stationary or in motion during the data acquisition (Block  208 ). Such motion could be due to a pattern the user is instructed to move the electronic device  100  in, such as a  FIG. 8 . Whether the magnetometer  102  was stationary or in motion is determined by comparing the range of the magnetic data to a threshold range. If the magnetometer  102  was stationary, the magnetic data is unsuitable for calibration purposes, and the method then returns to acquiring magnetic data (back to Block  202 ). 
         [0024]    If the magnetometer  102  was in motion during the data acquisition, a calibration status indicator is computed (Block  210 ). The calibration status indicator is computed as a function of the time elapsed since a last calibration, whether an anomaly was found and variation in total magnetic field. The calibration status indicator may also be computed as a function of the surroundings of the electronic device  100 , for example, determined by reviewing data collected by the magnetometer  102  over certain interval in past and calculating the mean and variation of those data values. The various thresholds are design choices, and they ultimately determine if the calibration status indicator at a given time indicates whether or not calibration should proceed (Block  212 ). If calibration is to not proceed, such as due to the last calibration still being considered valid, then the method returns to acquiring magnetic sensor measurement data (back to Block  202 ). 
         [0025]    If the calibration status indicator indicates that the last calibration is no longer valid, then the process of storing a unique magnetic data set for the calibration is started (Block  214 ). Unique magnetic data tuplet sets are extracted by comparing previously stored magnetic data to the current magnetic data from the magnetometer  102 . In particular, the time difference between the previously stored magnetic data and the current magnetic data from the magnetometer  102  is calculated, and the Euclidean distance between the current magnetic data and the previously stored magnetic data is calculated. Previously stored magnetic data older than a given threshold time is discarded, and items of the current magnetic data that are unique are stored. The purpose of this step is to have a magnetic measurement data set with a wide range of values (variation), and preferably with values evenly spaced apart in terms of Euclidean distance. 
         [0026]    Once the magnetic data set is extracted, whether the magnetic data set is sufficient for use in the calibration process is determined (Block  216 ). Details of this sufficiency check are now described with additional reference to  FIG. 3 . A number of unique samples or members of the magnetic data set is determined and compared with a sample number threshold (Block  216 A). If the number of unique samples is insufficient, the method returns to acquiring magnetic data (back to Block  202 ). 
         [0027]    If the number of unique samples is sufficient, then the range of each axis of the magnetic data set is compared to a threshold range (Block  216 B). If the range of each axis is not greater than the threshold range, then the method returns to acquiring magnetic data (back to Block  202 ). If the range of each axis is greater than the threshold range, then a sanity check is performed (Block  218 ). 
         [0028]    Details of this sanity check are now described with additional reference to  FIG. 4 . First, eigenvalues of cross correlation matrices of the magnetometer data are computed (Block  218 A). The produced eigenvalues represent the variance of the magnetic data along three orthogonal axes (which may or may not be different than the axes of the magnetometer  102 ). If the ratio of the major and minor eigenvalue is greater than a threshold ratio (Block  218 B), there is insufficient rotation along one axis for the magnetic data set to be used for calibration, or there is an excessively large variation along one axis which renders the magnetic data set undesirable for use for calibration, and the method returns to acquiring magnet data (Block  202 ). 
         [0029]    If the ratio is less than the threshold ratio, then the sanity check has passed, and the method proceeds to calibration (Block  220 ). The calibration is performed via ellipsoidal fitting, with parameters for a parabolic curve first being generated, and constraints being used to check if the parameters satisfy an ellipsoid constraint. Further details of the ellipsoidal fitting will be given below. 
         [0030]    After the calibration is performed, a consistency check is performed (Block  222 ) on new calibration parameters. The consistency check determines whether the newly calculated calibration parameters are consistent with previously stored calibration parameters and are within specific range. If the newly calculated calibration parameters are not consistent with the previously stored calibration parameters, based on a comparison of bias and scale factor, then it will not be stored, and the method returns to acquiring magnetic data (back to Block  202 ). Next, the newly calculated (and now stored at Block  228 ) calibration parameters are weighted together with the previously stored calibration parameters (Block  230 ). This weighting is performed as a function of the quality, consistency with rest of calibration parameters, and time elapsed between each set of calibration parameters and the present time. Calibration settings are then generated as a function of the weighted calibration parameters (Block  232 ), such as by computing the weighted mean of scale and bias. These results are then available for use by the processing device  104  in collecting data from the magnetometer  102 . Collected magnetometer values may then be used in generating user output, affecting user input, and in making user interface decisions and operations. 
         [0031]    Details of the calibration via ellipsoidal fitting will now be given. The magnetic data is affected by Hard Iron (HI) bias and Soft Iron (SI) bias. Mathematically, this can be represented as: 
         [0000]        {circumflex over (B)}= SI*( B   m −HI)   (1)
 
         [0000]    where B m  is the magnetic sensor measurement data from the magnetometer  102  which is affected by hard iron HI and soft iron SI, and B is true value. The HI will shift a generated sphere to nonzero origin and SI will deform the sphere to an ellipsoid. The total magnetic field can be represented as: 
         [0000]        {circumflex over (B)}   T   *{circumflex over (B)}=H   2    (2)
 
         [0000]      And 
         [0000]      ( B   m −HI) T (SI T *SI)*( B   m −HI)= H   2    (3)
 
         [0000]      ( B   m −HI) T   *R* ( B   m −HI)= H   2    (4)
 
         [0032]    Here R is a symmetric and square matrix. An ellipsoid fit algorithm would be able to compute the R matrix but there is an issue with computing the SI matrix from R, since there is no unique solution to R. Since the R matrix is symmetric and has 6 unknown parameters, and original SI matrix has 9 unknown variables, the SI matrix cannot be computed directly. 
         [0033]    Stated another way, when a sphere is rotated the result will still be a sphere. So ultimately angle information is lost due to the squaring operation. In order to overcome this issue, a constraint that one axis is perfectly aligned with original direction is applied. Using this constraint, the SI matrix can be represented in the following format: 
         [0000]    
       
         
           
             
               
                 
                   SI 
                   = 
                   
                     [ 
                     
                       
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             11 
                           
                         
                         
                           0 
                         
                         
                           0 
                         
                       
                       
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             21 
                           
                         
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             22 
                           
                         
                         
                           0 
                         
                       
                       
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             31 
                           
                         
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             32 
                           
                         
                         
                           
                             a 
                              
                             
                                 
                             
                              
                             33 
                           
                         
                       
                     
                     ] 
                   
                 
               
               
                 
                   ( 
                   5 
                   ) 
                 
               
             
           
         
       
     
         [0034]    The SI matrix can thus be computed from R by performing a U-D factorization. Rearranging terms in the form of a distorted ellipsoid results in: 
         [0000]      ε( B   x   m   , B   y   m   , B   z   m )= aB   x   m2   +bB   y   m2   +cB   z   m2 +2 dB   x   m   B   z   m +2 eB   x   m   B   y   m +2 fB   y   m   B   z   m +2 gB   y   m +2 hB   y   m +2 IB   y   m   +G= 0   (6)
 
         [0035]    The fitting of this conic equation can then be solved by minimizing the sum of squared distance ε(B x   m , B y   m , B z   m ), which can be represented as: 
         [0000]    
       
         
           
             
               
                 
                   β 
                   = 
                   
                     
                       
                         ∑ 
                         
                           i 
                           = 
                           1 
                         
                         N 
                       
                        
                       
                           
                       
                        
                       
                         
                           ε 
                            
                           
                             ( 
                             
                               
                                 B 
                                 xi 
                                 m 
                               
                               , 
                               
                                 B 
                                 yi 
                                 m 
                               
                               , 
                               
                                 B 
                                 zi 
                                 m 
                               
                             
                             ) 
                           
                         
                         2 
                       
                     
                     = 
                     0 
                   
                 
               
               
                 
                   ( 
                   7 
                   ) 
                 
               
             
           
         
       
     
         [0036]    There are many solutions of this minimization and to fit as an ellipsoid, the following condition should be satisfied by the coefficient: 
         [0000]      4( ab+bc+ac−d   2   −e   2   −f   2 )&gt;( a+b+c ) 2    (8)
 
         [0037]    The equation 8 can be written in following format: 
         [0000]      A T CA=λ
 
         [0000]    where A=[a,b,c,d,e,f,g,h,I,G]], λ is positive and C is: 
         [0000]    
       
         
           
             
               C 
                
               
                 ( 
                 
                   
                     1 
                      
                     
                       : 
                     
                      
                     6 
                   
                   , 
                   
                     1 
                      
                     
                       : 
                     
                      
                     6 
                   
                 
                 ) 
               
             
             = 
             
               [ 
               
                 
                   
                     
                       
                         
                           
                             - 
                             1 
                           
                         
                         
                           1 
                         
                         
                           1 
                         
                       
                       
                         
                           1 
                         
                         
                           
                             - 
                             1 
                           
                         
                         
                           1 
                         
                       
                       
                         
                           1 
                         
                         
                           1 
                         
                         
                           
                             - 
                             1 
                           
                         
                       
                     
                   
                   
                     
                       0 
                       
                         3 
                         × 
                         3 
                       
                     
                   
                 
                 
                   
                     
                       0 
                       
                         3 
                         × 
                         3 
                       
                     
                   
                   
                     
                       
                         
                           
                             - 
                             4 
                           
                         
                         
                           0 
                         
                         
                           0 
                         
                       
                       
                         
                           0 
                         
                         
                           
                             - 
                             4 
                           
                         
                         
                           0 
                         
                       
                       
                         
                           0 
                         
                         
                           0 
                         
                         
                           
                             - 
                             4 
                           
                         
                       
                     
                   
                 
               
               ] 
             
           
         
       
     
         [0038]    After solving the equation, parameters are obtained and then the locus, rotation and radii of the ellipsoid are computed. Once the computation is completed, the algorithm checks the fitness of the coefficients and the range of the scale factor. If both are within range, the algorithm has been a success. This algorithm will return the best possible ellipsoid rather than quadratic curve coefficients. 
         [0039]    It should be appreciated that the techniques described above provide for a magnetometer  102  that provides improved (i.e. more accurate and precise) results, and thus improve the function of the magnetometer  102  itself. It should also be appreciated that the various techniques described above must be performed more quickly than a human being could perform them on paper in order for the method to work. Indeed, the steps of the flowchart  200  of  FIG. 2  are to be performed in under 3 seconds, or in under 2 seconds. It should also be understood that since the processing device  104  is configured to perform the steps described herein, the various transistors inside have been biased and configured in a specific configuration, making the processing device  104 , as it functions herein, a specific purpose processing device  104 . 
         [0040]    The calibration settings are used either by the magnetometer  102  to adjust the data it collects, or by the processing device  104  to compute and provide calibrated magnetic field strength the data collected by the magnetometer  102 . The data collected by the magnetometer  102 , according to the calibration settings, may then be used for various functions, such as determining device orientation and determining device orientation with respect to Earth&#39;s magnet north. 
         [0041]    Many modifications and other embodiments will come to the mind of one skilled in the art having the benefit of the teachings presented in the foregoing descriptions and the associated drawings. Therefore, it is understood that various modifications and embodiments are intended to be included within the scope of the appended claims.