我想在车辆行驶时计算振动。我在onSensorChanged事件中获取此数据。我需要计算12hz,24hz和36hz的振动。
@Override
public void onSensorChanged(SensorEvent event) {
if (started) {
long timestamp = System.currentTimeMillis();
final float alpha = 0.8f;
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
accelerometer_data[0] = event.values[0] - gravity[0];
accelerometer_data[1] = event.values[1] - gravity[1];
accelerometer_data[2] = event.values[2] - gravity[2];
long differ = (timestamp - previousTime);
if (differ > 1500 ){
Log.e(Tag, rotation_per_second * accelerometer_data[0]+"--12hz");
Log.e(Tag, rotation_per_second *2* accelerometer_data[1]+ "--24hz");
Log.e(Tag, rotation_per_second *3* accelerometer_data[2]+"--36hz");
previousTime = timestamp;
}
else
{
//Log.e(Tag, "Difference = "+differ+"");
}
AccelData data = new AccelData(timestamp, accelerometer_data[0], accelerometer_data[1], accelerometer_data[2]);
sensorData.add(data);
}
}
rotation_per_second是车辆行驶时的频率。例如,如果车辆以60mph的速度移动,我将获得12hz的频率。现在我想从onSensorChanged事件计算12hz,24hz和36hz的幅度。