accelcal
Syntax
Description
[
returns matrix A
,b
] = accelcal(D
)A
and vector b
used to correct
uncalibrated accelerometer measurements based on the calibration data
D
.
After obtaining A
and b
, obtain the calibrated
data C
from uncalibrated data U
by using
C
= U
*A
+ b
,
where U
is a M-by-3 matrix and each row of
U
is an uncalibrated accelerometer measurement.
Examples
Calibrate Accelerometer Measurements
Create an imuSensor
object for generating measurement data. By default, the reference frame of the object is the north-east-down (NED) frame. Specify the accelerometer parameters so that the measurements contain a constant bias and some random noise.
accelParams = accelparams(ConstantBias=[.1 .2 -.1],...
NoiseDensity=1e-2*ones(1,3));
imu = imuSensor(Accelerometer=accelParams);
disp(imu.ReferenceFrame)
NED
Define the Euler angles for six calibration orientations and convert them to quaternions.
orients = [... 0 90 0 % xUp 0 0 -90 % yUp 0 180 0 % zUp 0 -90 0 % xDown 0 0 90 % yDown 0 0 0]; % zDown quats = quaternion(orients,"eulerd","ZYX","frame"); N = numel(quats);
Assume the external accelerations and angular velocities are both 0. Simulate the IMU sensor to get the calibration measurements.
exAcc = zeros(N,3); angVel = zeros(N,3); D = imu(exAcc,angVel,quats)
D = 6×3
-9.6490 0.2225 -0.1925
0.0146 -9.5593 0.0153
-0.0210 0.1928 -9.9271
9.9363 0.1840 -0.0210
0.0008 9.9094 -0.0655
0.2828 0.1528 9.7232
Use the accelcal
function to obtain the calibration parameters.
[A,b] = accelcal(D)
A = 3×3
1.0018 0.0019 -0.0087
0.0006 1.0078 0.0041
-0.0154 0.0020 0.9986
b = 1×3
-0.0956 -0.1852 0.0779
Verify the calibration parameters by using the calibration measurements.
DCali = D*A+b
DCali = 6×3
-9.7587 0.0199 -0.0298
-0.0872 -9.8187 0.0534
0.0365 -0.0111 -9.8339
9.8589 0.0196 -0.0284
-0.0875 9.8012 0.0535
0.0380 -0.0109 9.7852
Create some random orientations, obtain the accelerometer measurements, and calibrate the measurements.
M = 10; randomQuats = randrot(M,1); U = imu(zeros(M,3),zeros(M,3),randomQuats); C = U*A+b
C = 10×3
9.1400 3.5374 -1.3008
-7.1185 -6.8126 -0.7088
7.1372 -6.8065 -0.5943
-7.9362 1.5605 5.6203
7.4397 -2.3143 -6.2363
7.0758 -4.0794 -5.7321
3.1250 -5.4306 7.2655
0.8261 -9.7286 1.3509
0.8486 2.8606 -9.2705
-2.4922 8.5000 -3.9532
Input Arguments
D
— Measurements at six calibration orientations
N-by-3 matrix
Measurements at the six calibration orientations of the accelerometer, specified as an N-by-3 matrix. N is the total number of measurements. Each row of the matrix is a measurement at one of the six calibration orientations of the accelerometer, as shown in Accelerometer Calibration Orientations. For best results, the matrix should contain an equal number of measurements for all the six orientations.
When interpreting the data in D
, the function by default
assumes that the Earth gravity constant g
is
9.81m/s2 or 1, whichever is closer to the mean of the norm
of the data.
Data Types: single
| double
XUP
— Measurements at x-up orientation
N1-by-3 matrix
Measurements at the x-up orientation of the accelerometer, specified as an N1-by-3 matrix. N1 is the total number of x-up measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the x-up orientation.
Data Types: single
| double
XDOWN
— Measurements at x-down orientation
N2-by-3 matrix
Measurements at the x-down orientation of the accelerometer, specified as an N2-by-3 matrix. N2 is the total number of x-down measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the x-down orientation.
Data Types: single
| double
YUP
— Measurements at y-up orientation
N3-by-3 matrix
Measurements at the y-up orientation of the accelerometer, specified as an N3-by-3 matrix. N3 is the total number of y-up measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the y-up orientation.
Data Types: single
| double
YDOWN
— Measurements at y-down orientation
N4-by-3 matrix
Measurements at the y-down orientation of the accelerometer, specified as an N4-by-3 matrix. N4 is the total number of y-down measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the y-down orientation.
Data Types: single
| double
ZUP
— Measurements at z-up orientation
N5-by-3 matrix
Measurements at the z-up orientation of the accelerometer, specified as an N5-by-3 matrix. N5 is the total number of z-up measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the z-up orientation.
Data Types: single
| double
ZDOWN
— Measurements at z-down orientation
N6-by-3 matrix
Measurements at the z-down orientation of the accelerometer, specified as an N6-by-3 matrix. N6 is the total number of z-down measurements. Each row of the matrix is a measurement of the accelerometer. See the Accelerometer Calibration Orientations section for the definition of the z-down orientation.
Data Types: single
| double
g
— Earth gravity constant
positive scalar
Earth gravity constant, specified as a positive scalar. If you do not specify this
argument, the function assumes the Earth gravity constant g
is
9.81m/s2 or 1, whichever is closer to the mean of the norm
of the data in D
.
Example: 9.807
Data Types: single
| double
Output Arguments
A
— Calibration matrix
3-by-3 matrix
Calibration matrix, returned as a 3-by-3 matrix.
Data Types: single
| double
b
— Calibration offset vector
1-by-3 vector
Calibration offset vector, returned as a 1-by-3 vector.
Data Types: single
| double
More About
Accelerometer Calibration Orientations
To obtain the measurement data for calibrating the accelerator, align the orientation of the accelerometer measurement frame (X-Y-Z) with one of the six orientations shown in this diagram. For example, to obtain an x-up measurement, align the positive-X direction of the accelerator measurement frame in the opposite direction of the gravity force as shown in the first figure.
If the accelerometer does not have any calibration errors and its measurement frame is perfectly aligned as shown in the figure, you can obtain ideal measurements in this table.
Orientation | aX | aY | aZ |
---|---|---|---|
X-Up | -g | 0 | 0 |
X-Down | +g | 0 | 0 |
Y-Up | 0 | -g | 0 |
Y-Down | 0 | +g | 0 |
Z-Up | 0 | 0 | -g |
Z-Down | 0 | 0 | +g |
In the table, aX,
aY, and
aZ are the X-, Y-, and Z-acceleration
components, respectively. g
is the local Earth gravity constant.
References
[1] AN4508 Application Note: Parameters and Calibration of a Low-G 3-Axis Accelerometer.
Version History
Introduced in R2023b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)