Sampling frequency : Swift on MAC OSX

edited September 2017 in General
I am using Swift to read the sensor data, as follows:

    device.accelerometer?.sampleFrequency = 100;
    device.gyro?.sampleFrequency = 100;
    device.accelerometer?.dataReadyEvent.startNotificationsAsync(handler: { (obj, error) in
        if let obj = obj {
            let toWrite = "\(obj.x)," + "\(obj.y)," + "\(obj.z),";
            print(toWrite);
        }
    });
                
    device.gyro?.dataReadyEvent.startNotificationsAsync(handler: { (obj, error) in
        if let obj = obj {
            let toWrite = "\(obj.x)," + "\(obj.y)," + "\(obj.z),";
            print(toWrite);
        }
     })

The problem that I am facing is that never am I getting a sample rate of 100Hz on either medium. When logging both the gyro and the accelero, I get 5~Hz on each . When choosing one vs the other, I can get 17Hz. ( Seems that the sampling frequency I set has no effect on the outcome.

Thoughts?

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px}
span.s1 {color: #000000}
span.s2 {color: #272ad8}
span.s3 {color: #4f8187}
span.s4 {color: #31595d}
span.s5 {color: #ba2da2}
span.s6 {color: #d12f1b}
span.s7 {color: #3e1e81}
span.s8 {color: #703daa}

Comments

  • edited September 2017
    Here is some output that I am getting that I consider weird: ( Note, I set the sampleFrequency to 30, loggin my accelerometer data ~ and gyro data at the same time. Only accelero is shown ))

    x,y,z,time,sample
    0.04345703125,-0.05712890625,1.0244140625,2017-09-30T12:34:05.012,125
    0.04150390625,-0.0576171875,1.0234375,2017-09-30T12:34:05.132,126
    0.04345703125,-0.05712890625,1.0234375,2017-09-30T12:34:05.252,127
    0.04150390625,-0.0556640625,1.02490234375,2017-09-30T12:34:05.492,128
    0.04150390625,-0.05712890625,1.025390625,2017-09-30T12:34:05.612,129
    0.041015625,-0.05615234375,1.02685546875,2017-09-30T12:34:05.732,130
    0.041015625,-0.05712890625,1.02392578125,2017-09-30T12:34:05.852,131
    0.041015625,-0.0576171875,1.02490234375,2017-09-30T12:34:05.972,132
    0.04345703125,-0.05712890625,1.02587890625,2017-09-30T12:34:05.973,133

    It makes absolutelly no sense to me why I am getting 9 samples, when I said 30... lol ( 9 samples is a happy path in this log, almost all other sample sets range to around 5 Hz ... )
  • https://mbientlab.com/iosdocs/latest/advanced_features.html#high-frequency-streaming

    You will also want to adjust the connection parameters.  Not sure if OSX has any weird connection interval restrictions but setting both max and min connection intervals to 20ms should suffice.

  • edited October 2017
    Hi Eric. Setting the connection parameters fixes the issue. I am now able to capture a lot more packets.

    However, the catch here is that I cannot limit the number of samples I am getting. For example, I set the sampling frequency to 30. With the connection interval set to 20ms, I now get more than 30 samples. ( 38 - 45 ) Staying focused on 30 Hz, how can I ensure that I get 30 samples exactly? ( +-2 samples is not a big deal. += 15 is ) While this is a substantial improvement on my original issue, it is still a bit away from where I want to be. ( Note: setting the ms rate to 33 does not solve the problem )
  • You can't, 30Hz is not a native sampling frequency of the accelerometer.  Supported ODRs for the BMI160 are listed in the bmi160.h header file.

  • ah, you are right. Thanks Eric! That answers all of my questions.
This discussion has been closed.