Abdul Samad
Abdul Samad

Reputation: 5918

Maximum sampling rate for accelerometer in iphone

Does anybody know that what is the maximum sampling rate of the iphone accelerometer. I want to have have high update rate. i set it to updateInterval to 1.0/ 300.0 But it seems that i am not getting that much update rate.

So can any body tell me that what is the maximum update rate that we can get or how i can get the high update rate.

Upvotes: 3

Views: 6815

Answers (3)

owenfi
owenfi

Reputation: 2631

Despite the documentation saying The maximum frequency at which you can request updates is hardware-dependent but is usually at least 100 Hz. it looks to me like the maximum sample rate is still 100Hz.

My approach to figure out was taking the existing sample code for CoreMotion called MotionGraphs and adapting the startUpdates function to look like this:

func startUpdates() {
    guard let motionManager = motionManager, motionManager.isGyroAvailable else { return }

    sampleCount = 0
    let methodStart = Date()

    motionManager.gyroUpdateInterval = TimeInterval(1.0/100000.0) // Hardcoded to something verfy fast
    motionManager.startGyroUpdates(to: .main) { gyroData, error in
        self.sampleCount += 1
        //...view update code removed
        if (self.sampleCount >= 100) {
            let methodFinish = Date()
            let executionTime = methodFinish.timeIntervalSince(methodStart)
            print("Duration of 100 Gyro samples: \(executionTime)")
            self.stopUpdates()
        }
    }
}

I also set motionManager.deviceMotionUpdateInterval = TimeInterval(1.0/100000.0) for good measure (in case it is a global rate).

With that code in place for both Accelerometer and Gyroscope I confirm that an iPhone 8 on iOS 11.4 still maxes out right around 100Hz for both.

Duration of 100 Accelerometer samples: 0.993090987205505
Duration of 100 Accelerometer samples: 0.995925068855286
Duration of 100 Accelerometer samples: 0.993505954742432
Duration of 100 Accelerometer samples: 0.996459007263184
Duration of 100 Accelerometer samples: 0.996203064918518

Duration of 100 Gyro samples: 0.989820957183838
Duration of 100 Gyro samples: 0.985687971115112
Duration of 100 Gyro samples: 0.989449977874756
Duration of 100 Gyro samples: 0.988754034042358

Upvotes: 3

Sean Mayes
Sean Mayes

Reputation: 168

The max accelerometer and gyroscope sampling rate on the iPhone 6 is 100Hz. You can empirically test this yourself. Here is the code.

/******************************************************************************/
// First create and initialize two NSMutableArrays. One for accel data and one
// for gyro data. Then create and initialize CMMotionManager.  Finally,
// call this function

- (void) TestRawSensors
{
   speedTest = 0.0001; // Lets try 10,000Hz
   motionManager.accelerometerUpdateInterval = speedTest;
   motionManager.gyroUpdateInterval = speedTest;


    [motionManager startAccelerometerUpdatesToQueue: [NSOperationQueue currentQueue]
    withHandler: ^(CMAccelerometerData  *accelerometerData, NSError *error)
    {
       [rawAccelSpeedTest addObject: [NSNumber numberWithDouble: accelerometerData.timestamp]];
       [rawAccelSpeedTest addObject: [NSNumber numberWithDouble: accelerometerData.acceleration.x]];

       if (error)
       {
          NSLog(@"%@", error);
       }

       if (rawAccelSpeedTest.count > 100)
       {
          [motionManager stopAccelerometerUpdates];

          for (uint16_t i = 0; i < rawAccelSpeedTest.count; i+=2)
          {
             NSLog(@"Time: %f   Accel: %f", [rawAccelSpeedTest[i] doubleValue],
                                            [rawAccelSpeedTest[i+1] doubleValue]);
          }
       }
    }];


   [motionManager startGyroUpdatesToQueue: [NSOperationQueue currentQueue]
                              withHandler: ^(CMGyroData *gyroData, NSError *error)
    {
       [rawGryoSpeedTest addObject: [NSNumber numberWithDouble: gyroData.timestamp]];
       [rawGryoSpeedTest addObject: [NSNumber numberWithDouble: gyroData.rotationRate.x]];

       if (error)
       {
          NSLog(@"%@", error);
       }

       if (rawGryoSpeedTest.count > 100)
       {
          [motionManager stopGyroUpdates];

          for (uint16_t i = 0; i < rawGryoSpeedTest.count; i+=2)
          {
             NSLog(@"Time: %f   Rate: %f", [rawGryoSpeedTest[i] doubleValue],
                                           [rawGryoSpeedTest[i+1] doubleValue]);
          }

       }
    }];
}

Upvotes: 3

Kay
Kay

Reputation: 13146

Maybe duplicate. Look at

update frequency set for deviceMotionUpdateInterval it's the actual frequency?

Actual frequency of device motion updates lower than expected, but scales up with setting

The same should be valid if using old UIAccerometerDelegate interface.

Upvotes: 1

Related Questions