1
我正在研究使用android手機中的傳感器準確檢測用戶的腳步。我主要使用加速計傳感器來檢測腳踏。我使用了一種方法來獲取加速度計數據並搜索一種方法來去除加速度計數據中不需要的噪聲。我發現數據的線性化是一個好方法。但我沒有太清楚的想法如何去做。我認爲它是一種獲得中位值的方式。所以我沒有找到實時獲取中值的方法。任何人都可以建議我更好的lenearization方法來消除加速度計數據的噪音。android傳感器數據的線性化(加速度計)
這裏是我的代碼。(我使用了一個NChart庫畫一個圖表中我的加速度計數據。)
package com.android.gait;
import org.achartengine.GraphicalView;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private int count=0;
private static GraphicalView view;
private LineGraph line = new LineGraph();
private static Thread thread;
private SensorManager mSensorManager;
private Sensor mAccelerometer;
TextView title,tv,tv1,tv2;
RelativeLayout layout;
private static Point p;
static float m = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//get the sensor service
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
//get the accelerometer sensor
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
//get layout
layout = (RelativeLayout)findViewById(R.id.relative);
LinearLayout layout = (LinearLayout) findViewById(R.id.layoutC);
view= line.getView(this);
layout.addView(view);
//get textviews
title=(TextView)findViewById(R.id.name);
tv=(TextView)findViewById(R.id.xval);
tv1=(TextView)findViewById(R.id.yval);
tv2=(TextView)findViewById(R.id.zval);
thread = new Thread(){
int iniX=0;
public void run()
{
while(true)
{
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
iniX=+1;
line.addNewPoint(iniX,m);
view.repaint();
}
}
};
thread.start();
}
public final void onAccuracyChanged(Sensor sensor, int accuracy)
{
// Do something here if sensor accuracy changes.
}
@Override
public final void onSensorChanged(SensorEvent event)
{
count=+1;
// Many sensors return 3 values, one for each axis.
float x = event.values[0];
float y = event.values[1];
float z = event.values[2];
//get merged value
m = (float) Math.sqrt(x*x+y*y+z*z);
// p =MockData.getDataFromReceiver(count, m);
//display values using TextView
title.setText(R.string.app_name);
tv.setText("X axis" +"\t\t"+x);
tv1.setText("Y axis" + "\t\t" +y);
tv2.setText("Z axis" +"\t\t" +z);
}
@Override
protected void onResume()
{
super.onResume();
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause()
{
super.onPause();
mSensorManager.unregisterListener(this);
}
public void LineGraphHandler(View view){
}
}
這是使用任何庫嗎?我如何在編碼中使用它?抱歉。我新來android。這是我大學的一項研究。 – dit1679