Matlab社区

Matlab,社区和更多

使用Matlab Mobile获取来自Android设备传感器的数据

With the new MATLAB® Support Package for Android™ Sensors, you can now use MATLAB Mobile™ to acquire data from the sensors on your Android device. This data can be sent to a MATLAB session running on your computer for further analysis and visualization.

Contents

你问的是什么数据?

On Android devices, MATLAB Mobile supports data acquisition from motion sensors like the accelerometer as well as positional sensors like the GPS. A list of all sensors is shown below.

Matlab M金宝appobile的支持传感器列表

查看传感器数据

您可以通过选择来访问这些传感器传感器option from the drop-down menu in MATLAB Mobile. You can tap on a sensor to enable it and view related measurements. The screenshot below is the result of turning on the Accelerometer and Magnetometer.

Acceleration and Magnetic Field

Analyze Data with MATLAB

Displaying this data is cool, but to make this truly useful, you will want to perform further analysis and processing. Fortunately, the MATLAB Support Package for Android Sensors helps you do just that! It enables you to send sensor data to a MATLAB session on your computer. To do this:

  • 使用MATLAB连接器将MATLAB MOBILE连接到计算机。此功能仅支持Matlab R2014A及更金宝app高版本,因此请确保您处于兼容版本。
  • 为Android传感器安装MATLAB金宝app支持包。选择Add-ons从MATLAB TOOLSTRIP,然后选择Get Hardware Support Packages. This will open the support package installer. ChooseAndroid Sensors从列表中按照说明操作。
  • 要在设备和MATLAB上的传感器之间建立通信,请创建MobileDev对象,如下所示:
m = mobiledev;

Example: Counting Steps by Capturing Acceleration Data

The mobiledev object facilitates communication between the sensors on your Android device and the MATLAB session running on your computer. Let’s explore this workflow through an example that illustrates the collection of acceleration data and using it to count the number of steps taken.

第1步:打开加速度计
Once you have completed the 3 steps from the above section, go to MATLAB Mobile and turn on the accelerometer. You should see something akin to this:

Acceleration


You can also enable the sensor directly from MATLAB, by executing the following command:
m.accelerationsensorenabled = 1;
Step 2: Send Data to MATLAB
你注意到了启用了吗?开始发送按钮朝屏幕底部?点击它,瞧!您现在将数据发送到MATLAB。或者,您可以通过以下命令开始直接从MATLAB发送数据:
M.Logging = 1;
You can verify this in MATLAB, note the Current Sensor Values in the result:
m
m = mobiledev with properties: Connected: 1 Logging: 1 InitialTimestamp: '02-Oct-2014 21:53:26.707' AccelerationSensorEnabled: 1 (20 Logged values) AngularVelocitySensorEnabled: 0 MagneticSensorEnabled: 0 OrientationSensorEnabled: 0 PositionSensorEnabled: 0 Current Sensor Values: Acceleration: [0.2631 5.9226 8.1850] (m/s^2)
第3步:停止获取数据并检索日志
走在你的校园/ home /地板德维克e. Once you are satisfied, stop sending this data to MATLAB. You can either tap on theStop Sendingbutton on MATLAB Mobile, or issue the following command in MATLAB:
m.logging = 0;
To retrieve the data, use the accellog variable:
[A,T] = Accellog(M);
Step 4: Plot Raw Sensor Data
检索到Logged加速度数据后,您可以在Matlab中绘制它:
plot(t, a); legend('X','Y','Z');Xlabel('相对时间(s)');ylabel('加速度(m / s ^ 2)');

matlab_mobile_sensors_01


计算幅度以将x,y和z向量转换为标量值。然后,绘制它。
x = a(:,1);Y = A(:,2);z = a(:,3);%计算和绘图幅度。mag = sqrt(sum(x.^2 + y.^2 + z.^2, 2)); plot(t, mag); xlabel('Time (s)');ylabel('加速度(m / s ^ 2)');

Acceleration Magnitude Plot


To remove constant effects such as gravity, you can subtract the mean from this data.
% Accounting for gravity.magnog = mag  - 平均值(mag);% Plot magnitude.plot(t,magnog);Xlabel('Time (s)');ylabel('加速度(m / s ^ 2)');

加速度幅度图(移除重力)


The plotted data is now centered on zero, and shows peaks which correspond to a step taken while walking.

第5步:计数拍摄的步骤数
要确定所采取的步骤数,您可以使用信号处理工具箱查找功能。在该示例中,我们仅在一个标准偏差上高于一个标准偏差的峰值处理。应该通过实验调整该阈值,以匹配一个人的运动水平,而楼层表面的硬度等。
%使用FindPeaks来确定当地的最大值。minPeakHeight = std(magNoG); [pks, locs] = findpeaks(magNoG,'MINPEAKHEIGHT', minPeakHeight);
The number of steps taken is the number of peaks:
numsteps = numel(pks)
numSteps = 15
最后,您还可以在加速度幅度数据的情节上识别这些位置:
hold;% Place a red marker on the locations that correspond to peaks.绘图(T(LOC),PKS,'r','Marker','v','linestyle','none');title('Counting Steps');Xlabel('Time (s)');ylabel('加速度,重力去除(m / s ^ 2)');holdoff;

加速度幅度图(峰值)


Step 6: Clean Up
完成后,请确保关闭加速度传感器并清除MobileDev对象。
m.AccelerationSensorEnabled = 0; clearm;

Try it out!

要了解有关从移动设备上的传感器获取数据的更多信息,请参阅以下链接:

您获取的数据是哪些数据,以及您对该数据的分析中获得了哪些见解?

Let us know by leaving a comment below.

发布ed with MATLAB® R2014b

|
  • print
  • 发送电子邮件

注释

要发表评论,请点击这里要登录您的MathWorks帐户或创建新的。