0

I've been using Sony Smartwatch 3 for recording accelerometer data on long time periods (8 hour on average). Below is the main code block: ax,ay and az are arraylists for storing the sensor values and ta is an arraylist with the corresponding timestamps.

private void startMeasurement() {
    mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));
    Log.d("lister", "listeners");
    Sensor accelerometerSensor = mSensorManager.getDefaultSensor(SENS_ACCELEROMETER);

    // Register the listener
    if (mSensorManager != null) {
        mSensorManager.registerListener(this, accelerometerSensor,25000);
    }
}

    @Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == SENS_ACCELEROMETER){
        ax.add(event.values[0]);
        ay.add(event.values[1]);
        az.add(event.values[2]);
        ta.add(System.currentTimeMillis());
    }

}

public void write(){
    String timeStamp = new SimpleDateFormat("yyMMdd_HHmmss").format(Calendar.getInstance().getTime());
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/sensor_data/" + timeStamp + ".csv");
    try{
        FileWriter fw = new FileWriter(file);
        BufferedWriter buffWriter = new BufferedWriter(fw,50*1024);
        for(int i=0;i<ax.size();i++){
            buffWriter.write(String.valueOf(ax.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(ay.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(az.get(i)));
            buffWriter.write(",");
            buffWriter.write(String.valueOf(ta.get(i)));
            buffWriter.write("\n");
        }
        buffWriter.flush();
        buffWriter.close();
    }catch (IOException e){
        e.printStackTrace();
    }

}

When taking a look at the time difference between samples I notice an increase in that time after some time recording the data. In the link below you can see the plot of the time difference between samples in seconds. enter image description here

Why is it happening that the difference jumps abruptly to 50 after some time recording?

Vic Seedoubleyew
  • 9,888
  • 6
  • 55
  • 76

1 Answers1

2

Ended up solving the problem by using Android's PowerManager and PARTIAL_WAKE_LOCK. It consumes more battery but I really need the sampling frequency to be kept nearly constant.