3

I have to collect accelerometer data from my Android phone, so I have made a little program to do that.

After some tests, I have found that my Nexus S accelerometer's rate is always 50 values per second when the phone is active, and 6 values per second when it is asleep (with a PARTIAL_WAKE_LOCK), whatever the rate I ask for (NORMAL, UI, GAME or FASTEST).

So I decided to install an application found on the Internet which tests the rate of the accelerometer : http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code

But I got the same "error" : whatever the rate I ask for, it is always 50 values per second when the phone is active.

I don't understand why my phone behaves this way. Is it a problem :

  • related to the Nexus S ?
  • specific to my phone ?
  • related to Android 4 ?

EDIT : I have tested the program on another Nexus S (Android 4), and I have the same problem. So it seems to eliminate one of the possibilities listed above: it is not related only to my phone.

Romain Guidoux
  • 2,943
  • 4
  • 28
  • 48
  • 1
    I have tried the code on a Asus transformer tablet and i have the same problem. All sensor delay use 50 Hz of frecuency. I will look for the answer too. – vgonisanz Feb 20 '12 at 10:02
  • 1
    You can try it on various configurations using emulators in order to determine whether it's OS dependent or device dependent. My bet would be that the value depends on your hardware and canno't be changed... Also, read this: http://stackoverflow.com/questions/4224223/android-how-to-increase-accelerometer-sampling-rate – Amokrane Chentir Feb 28 '12 at 12:32
  • Thanks, I will try with the emulators ! – Romain Guidoux Feb 28 '12 at 14:37

4 Answers4

6

I have performed some tests on different smartphones. Here are the results:

Samsung Galaxy Teos
-------------------
* When awake
    Normal: 4.17 Hz
    UI: 8.43 hz
    Game: 16.93 Hz
    Fastest: 109.42 Hz

* When asleep
    The phone sends null values (0), whatever the mode I chose


Samsung Nexus S
---------------
* When awake
    Normal: 49.51 Hz
    UI: 49.51 hz
    Game: 49.51 Hz
    Fastest: 49.51 Hz

* When asleep
    6.06 Hz, whatever the mode I chose

LG Nexus 5
----------
* When awake
    Normal: 15.39 Hz
    UI: 15.4 Hz
    Game: 50.05 Hz
    Fastest: 196.74 Hz

* When asleep
    Normal: 4.96 Hz
    UI: 15.41 Hz
    Game: 50.12 Hz
    Fastest: 198.53 Hz

LG Nexus 4
----------
* When awake
    Normal: 15.75 Hz
    UI: 15.74 Hz
    Game: 48.86 Hz
    Fastest: 195.85 Hz

* When asleep
    Normal: 5.5 Hz
    UI: 15.74 Hz
    Game: 49.16 Hz
    Fastest: 196.75 Hz


Samsung Galaxy Nexus
--------------------
* When awake
    Fastest: 125 Hz

* When asleep
    It sends data


Samsung Galaxy Note 2
---------------------
* When awake
    Fastest: 100 Hz

* When asleep
    The phone does not send anything


Samsung Galaxy S3 and S3 Mini
-----------------------------
* When awake
    Fastest: 100 Hz

* When asleep
    Fastest: 100 Hz


HTC Wildfire
------------
* When awake
    Normal: 4 Hz
    UI: 12 hz
    Game: 22.2 Hz
    Fastest: 38.40 Hz

* When asleep
    The phone does not send anything, whatever the mode I chose


HTC Desire
----------
* When awake
    Normal: 4.36 Hz
    UI: 11.9 hz
    Game: 23.3 Hz
    Fastest: 47.27 Hz

* When asleep
    The phone does not send anything, whatever the mode I chose

Note that the tests have been performed using a partial wake lock. Without it, the Nexus S provides no data at all when it is asleep.

There is also a useful list of smartphones which accelerometers send (or not) compatible data when asleep: http://www.saltwebsites.com/2012/android-accelerometers-screen-off

Romain Guidoux
  • 2,943
  • 4
  • 28
  • 48
  • Hi Romain, can you give me some pointers as to how did u test rates for different phones on various modes? – R3D3vil Apr 11 '12 at 23:15
  • Hi Nisarg, I used this application to test device frequencies: http://samoht.fr/tuto/accelerometers-frequency-on-android-with-code Fortunately my company owns several devices so I can have tested the ones I quote in my answer. – Romain Guidoux Apr 12 '12 at 07:38
  • Hi Romain, Thanks a lot... I will try this one!! – R3D3vil Apr 12 '12 at 23:27
3

Don't connect your phone to a PC via USB while taking data because during collection data is logged in the SD card only. When the phone is connected to PC via USB no file can be saved in SD card.

So try disconnecting the USB while collecting the data.

sarnold
  • 102,305
  • 22
  • 181
  • 238
aps109
  • 167
  • 1
  • 3
  • 15
  • I have tested your app and indeed the frequency is about 16-17 Hz. How do you do that ? Is it by checking the values in the onSensorChanged() method ? If so, it does not solve my problem. – Romain Guidoux Mar 09 '12 at 09:46
  • By the way, answer me with comments instead of answers ;) – Romain Guidoux Mar 09 '12 at 09:47
  • we did not use SensorChanged() method. Instead we fetched the maximum number of samples through the code(by using fastest) and the we performed down sampling through an algorithm corresponding to 15 samples per second. Hope this works for you too. – aps109 Mar 10 '12 at 18:08
  • Thanks, but I don't understand how you can 1) fetch the maximum number of samples and 2) perform down sampling without getting accelerometer values (which, as far as I know, can only be done by registering a listener and implementing `onSensorChanged()`) – Romain Guidoux Mar 10 '12 at 19:36
  • We used the command SENSOR_DELAY_FASTEST to fetch maximum sampling rate from accelerometer. Then csv file was updated at intervals corresponding to (1/15). In short we are taking maximum number of samples from the accelerometer, but only some of the samples are logged into the csv file. Samples are logged after (1/15)s whereas accelerometer data is fetched after (1/90)s. – aps109 Mar 11 '12 at 04:19
  • ok, so you implement `onSensorChanged()` and write only the values you want. Indeed, this method is the only way you can get the accelerometer values (after having registered with `sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST)`). But that is not what I want: I want the accelerometer's device to be the one I want in order to save battery life (`SENSOR_DELAY_FASTEST` consums more battery than `SENSOR_DELAY_NORMAL`). – Romain Guidoux Mar 11 '12 at 08:51
  • We don't know any other method to put a constraint on sampling rate. – aps109 Mar 11 '12 at 09:32
1

Unfortunately as suggested by other answers, the delay (or sampling rate) that you set is only a suggestion (for the system) of the minimum your application requires however, this can change drastically depending on other applications running or your device entering on power saving modes (turning off cpu etc). One way I was able to get a somewhat good sampling rate was by recording my data from a service, making the service a foreground service and having a power lock with the flag PARTIAL_WAKE_LOCK.

I put the code in this gist https://gist.github.com/julian-ramos/6ee7ad8a74ee4b442530

That gist has way more code than you need but just pay attention to the next two methods

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
//        //Power management
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
        wl.acquire();
.....}

The above code prevents the OS to turn off the CPU

Now to make this service a foreground service

NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("Title")
                        .setContentText("hola")
                        .setContentIntent(viewPendingIntent);



        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

        not=notificationBuilder.build();
        notificationManager.notify(notificationId,not );
        startForeground(notificationId, not);

The above code makes the service a priority for the OS unlike a normal service. Examples of a foreground service are music players for instance.

With this code I have been able to get the sampling rate I need even after the watch turn's off the screen automatically.

Juli
  • 1,011
  • 8
  • 16
0

check this app we have fixed sampling frequency at 14-15 irrespective of device model https://market.android.com/details?id=singh.pal.ajeet&feature=search_result#?t=W251bGwsMSwxLDEsInNpbmdoLnBhbC5hamVldCJd for any assistance mail us at developer.virtuoid@gmail.com