introduction to simulating imu measurements -凯发k8网页登录
this example shows how to simulate inertial measurement unit (imu) measurements using the imusensor
system object. an imu can include a combination of individual sensors, including a gyroscope, an accelerometer, and a magnetometer. you can specify properties of the individual sensors using gyroparams
, accelparams
, and magparams
, respectively.
in the following plots, unless otherwise noted, only the x-axis measurements are shown. use the sliders to interactively tune the parameters.
default parameters
the default parameters for the gyroscope model simulate an ideal signal. given a sinusoidal input, the gyroscope output should match exactly.
params = gyroparams
params = gyroparams with properties: measurementrange: inf rad/s resolution: 0 (rad/s)/lsb constantbias: [0 0 0] rad/s axesmisalignment: [3x3 double] % noisedensity: [0 0 0] (rad/s)/√hz biasinstability: [0 0 0] rad/s randomwalk: [0 0 0] (rad/s)*√hz temperaturebias: [0 0 0] (rad/s)/°c temperaturescalefactor: [0 0 0] %/°c accelerationbias: [0 0 0] (rad/s)/(m/s²)
% generate n samples at a sampling rate of fs with a sinusoidal frequency % of fc. n = 1000; fs = 100; fc = 0.25; t = (0:(1/fs):((n-1)/fs)).'; acc = zeros(n, 3); angvel = zeros(n, 3); angvel(:,1) = sin(2*pi*fc*t); imu = imusensor('samplerate', fs, 'gyroscope', params); [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('ideal gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
hardware parameter tuning
the following parameters model hardware limitations or defects. some can be corrected through calibration.
measurementrange
determines the maximum absolute value reported by the gyroscope. larger absolute values are saturated. the effect is shown by setting the measurement range to a value smaller than the amplitude of the sinusoidal ground-truth angular velocity.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.measurementrange = 0.5; % rad/s [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('saturated gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
resolution
affects the step size of the digital measurements. use this parameter to model the quantization effects from the analog-to-digital converter (adc). the effect is shown by increasing the parameter to a much larger value than is typical.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.resolution = 0.5; % (rad/s)/lsb [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('quantized gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
axesmisalignment
is the amount of skew in the sensor axes. this skew normally occurs when the sensor is mounted to the pcb and can be corrected through calibration. the effect is shown by skewing the x-axis slightly and plotting both the x-axis and y-axis.
imu = imusensor('samplerate', fs, 'gyroscope', params); xmisalignment = 2; % percent imu.gyroscope.axesmisalignment = [xmisalignment, 0, 0]; % percent [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1:2), '--', t, gyrodata(:,1:2)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('misaligned gyroscope data') legend('x (ground truth)', 'y (ground truth)', ... 'x (gyroscope)', 'y (gyroscope)')
constantbias
occurs in sensor measurements due to hardware defects. since this bias is not caused by environmental factors, such as temperature, it can be corrected through calibration.
imu = imusensor('samplerate', fs, 'gyroscope', params); xbias = 0.4; % rad/s imu.gyroscope.constantbias = [xbias, 0, 0]; % rad/s [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('biased gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
random noise parameter tuning
the following parameters model random noise in sensor measurements. more information on these parameters can be found in the inertial sensor noise analysis using allan variance example.
noisedensity
is the amount of white noise in the sensor measurement. it is sometimes called angle random walk for gyroscopes or velocity random walk for accelerometers.
rng('default') imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.noisedensity = 0.0125; % (rad/s)/sqrt(hz) [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('white noise gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
biasinstability
is the amount of pink or flicker noise in the sensor measurement.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.biasinstability = 0.02; % rad/s [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('bias instability gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
randomwalk
is the amount of brownian noise in the sensor measurement. it is sometimes called rate random walk for gyroscopes or acceleration random walk for accelerometers.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.randomwalk = 0.091; % (rad/s)*sqrt(hz) [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('random walk gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
environmental parameter tuning
the following parameters model noise that arises from changes to the environment of the sensor.
temperaturebias
is the bias added to sensor measurements due to temperature difference from the default operating temperature. most sensor datasheets list the default operating temperature as 25 degrees celsius. this bias is shown by setting the parameter to a non-zero value and setting the operating temperature to a value above 25 degrees celsius.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.temperaturebias = 0.06; % (rad/s)/(degrees c) imu.temperature = 35; [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('temperature-biased gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
temperaturescalefactor
is the error in the sensor scale factor due to changes in the operating temperature. this causes errors in the scaling of the measurement; in other words smaller ideal values have less error than larger values. this error is shown by linearly increasing the temperature.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.temperaturescalefactor = 3.2; % %/(degrees c) standardtemperature = 25; % degrees c temperatureslope = 2; % (degrees c)/s temperature = temperatureslope*t standardtemperature; gyrodata = zeros(n, 3); for i = 1:n imu.temperature = temperature(i); [~, gyrodata(i,:)] = imu(acc(i,:), angvel(i,:)); end figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('temperature-scaled gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
accelerationbias
is the bias added to the gyroscope measurement due to linear accelerations. this parameter is specific to the gyroscope. this bias is shown by setting the parameter to a non-zero value and using a non-zero input acceleration.
imu = imusensor('samplerate', fs, 'gyroscope', params); imu.gyroscope.accelerationbias = 0.3; % (rad/s)/(m/s^2) acc(:,1) = 1; [~, gyrodata] = imu(acc, angvel); figure plot(t, angvel(:,1), '--', t, gyrodata(:,1)) xlabel('time (s)') ylabel('angular velocity (rad/s)') title('acceleration-biased gyroscope data') legend('x (ground truth)', 'x (gyroscope)')
see also
| | |