%% Generate Magnetometer Data from Stationary Inputs
% Generate magnetometer data for an imuSensor object from stationary inputs.
% Generate a magnetometer parameter object with a maximum sensor reading of 1200 {\rm{\mu T}} and a resolution of 0.1 {\rm{\mu T/LSB}}. The constant offset bias is 1 {\rm{\mu T}}. The sensor has a power spectral density of\;\left(\frac{\left\lbrack 0\ldotp 6\;\;0\ldotp 6\;\;0\ldotp 9\right\rbrack }{\sqrt{100}}\right) {\rm{\mu T/}}\sqrt {{\rm{Hz}}}. The bias from temperature is [0.8 0.8 2.4] {\rm{\mu T/}}{}^{\rm{0}}{\rm{C}}. The scale factor error from temperature is 0.1 %{\rm{ /}}{}^{\rm{0}}{\rm{C}}.

params = magparams('MeasurementRange',1200,'Resolution',0.1,'ConstantBias',1,'NoiseDensity',[0.6 0.6 0.9]/sqrt(100),'TemperatureBias',[0.8 0.8 2.4],'TemperatureScaleFactor',0.1);

% Use a sample rate of 100 Hz spaced out over 1000 samples. Create the imuSensor object using the magnetometer parameter object.
%

Fs = 100;
numSamples = 1000;
t = 0:1/Fs:(numSamples-1)/Fs;

imu = imuSensor('accel-mag','SampleRate', Fs, 'Magnetometer', params);

% Generate magnetometer data from the imuSensor object.
%

orient = quaternion.ones(numSamples, 1);
acc = zeros(numSamples, 3);
angvel = zeros(numSamples, 3);
 
[~, magData] = imu(acc, angvel, orient);

% Plot the resultant magnetometer data.
%

plot(t, magData)
title('Magnetometer')
xlabel('s')
ylabel('\mu T')

% Copyright 2018 The MathWorks, Inc.
%