Help With Mapping IMU Data to Time

Hello All! This is my first post so sorry if this is not the right section. Anyways I am having problems with an IMU project I am working on. I am using the Intel Curie Module built into the Arduino 101 board as the IMU. Basically what I am having trouble with is figuring out of how to map time to the data points (three accelerator values and three gyroscope readings). I am also transferring this data over to MatLab via serial.write(). So there is an function with in the IMU library that allows you to set the sampling frequency of the IMU itself. However, the baud rate seems to be dictating how fast the data comes in.

Example: For tests of the same time duration, if I set the IMU sampling rate to 1,600Hz w/ a baud rate of 250,000 I get the around the same number of data points as if I set the IMU samping rate to 25Hz w/ a baud rate of 250,000.

Regardless of the settings, the data seemed to be real time when I just had it going to the arduino serial monitor. As an example of what I would ideally want it to do: for a 1 sec test run at 50Hz I would want 50 data point sets, and for a 1 sec test run at 100Hz I would want 100 data point sets and so on. This way I could easily figure out the the time differential between each data point. With the way it is now, changing the IMU's sampling rate doesn't seem to effect the number of data points I end up with, and i dont know how to map it to time. Below is my code for your reference. I don't think I am maxing out the serial connection speed because I believe I am transmitting 120 bits (each of the six 16 bit ints requires 20 bits to send including start and stop bits). 250,000/120 = 2083 which should be the max number of readings I can take per sec (Hz) without overwhelming the serial communication rate. I apologize if I missing something obvious, I am very new to this and am still trying to learn how things work! Thanks

#include "CurieIMU.h"

int ax, ay, az;         // accelerometer values
int gx, gy, gz;         // gyrometer values

const int ledPin = 13;      // activity LED pin
boolean blinkState = false; // state of the LED

int calibrateOffsets = 1; // int to determine whether calibration takes place or not
int i = 0;

void setup() {
  Serial.begin(250000); // initialize Serial communication
  while (!Serial);    // wait for the serial port to open

  // initialize device
  CurieIMU.begin();

  CurieIMU.setGyroRate(6); //set gyro sampling rate to 100Hz
  CurieIMU.setAccelRate(6); //set accelerometer sampling rate to 100Hz;
  
  // use the code below to calibrate accel/gyro offset values
  if (calibrateOffsets == 1) {
   
    delay(5000);

    //Calibrates Gyro and Accel to respective values
    CurieIMU.autoCalibrateGyroOffset();
    CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0);
    CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1);
  }
  
  // configure Arduino LED for activity indicator
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read raw accel/gyro measurements from device
  CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz);

  // send acceleration values to serial monitor in binary
  Serial.write(lowByte(ax));
  Serial.write(highByte(ax));
  Serial.write(lowByte(ay));
  Serial.write(highByte(ay));
  Serial.write(lowByte(az));
  Serial.write(highByte(az));

  //send gyro values to serial monitor in binary
  Serial.write(lowByte(gx));
  Serial.write(highByte(gx));
  Serial.write(lowByte(gy));
  Serial.write(highByte(gy));
  Serial.write(lowByte(gz));
  Serial.write(highByte(gz));
 
  // blink LED to indicate activity
  blinkState = !blinkState;
  digitalWrite(ledPin, blinkState);
}

EDIT* So I just ran a test with the IMU set at 100 Hz for 5 seconds (hand timed so not exact). I got 4430 data points. So 4430/5 = 886 Hz, which is neither near the sampling rate I set nor the max serial communication rate.

Along with each group of six data points, send the value of the millis() timer, read out when the data points were collected. That will give you an approximate time stamp.

Thank you for your suggestion! I will look into it. I am still concerned about why this is happening in the first place though.... Can anyone shed some light on the situation?