source: internals/2016/screencastmultiplayergame_control/trunk/Android_Sensors_Data_Extraction.m @ 16369

Last change on this file since 16369 was 16369, checked in by jesteves, 4 years ago

test

File size: 4.2 KB
Line 
1
2
3
4%% Set up connection
5connector on josepmesteves;
6
7%% Set up data acquisition
8
9% Create link to mobile device
10clear m
11m = mobiledev
12
13% Enable sensors
14m.AccelerationSensorEnabled = 1;
15m.AngularVelocitySensorEnabled = 1;
16m.OrientationSensorEnabled = 1;
17
18% Set Sampling Rate: 'Low' (0.988Hz), 'Medium' (9.9Hz), 'High' (200Hz)
19m.SampleRate = 'High';
20
21pause(2);
22
23% Start acquiring data
24m.Logging = 1;
25
26% Determine acquisition interval
27pause(60);
28
29% Stop acquiring data
30m.Logging = 0;
31
32%% Retrieve logged data
33[acc, t_acc] = accellog(m);
34[angvel, t_angvel] = angvellog(m);
35[orient, t_orient] = orientlog(m);
36
37%% Plot
38
39% Choose what to plot
40data_to_plot=1;
41
42
43if (data_to_plot == 1)
44    close all
45    figure
46    plot(t_acc, acc)
47    title('Acceleration')
48    legend('X axis', 'Y axis', 'Z axis')
49   
50    % Filtering the signal
51    constant15=0.2; % (1-0.2)/0.2 = 4 samples delay
52    signal_for_LP_filtering = acc(:,3);
53    filtered_value(1) = signal_for_LP_filtering(2);
54    for i= 1 +1 : length(t_acc)
55        filtered_value(i) = filtered_value(i-1) + constant15 * (signal_for_LP_filtering(i) - filtered_value(i-1));
56    end
57    figure
58    hold on
59    plot(t_acc, acc(:,3), 'b')
60    plot(t_acc, filtered_value, '.r')
61    legend('Z Acceleration', 'Z Acceleration Filtered')
62    title('Z Acceleration')
63    xlim([32,50])
64   
65end
66
67if (data_to_plot == 2 || data_to_plot == 4)
68    figure
69    plot(t_angvel, angvel)
70    title('Angular Velocity')
71    legend('X axis (Pitch)', 'Y axis (Roll)', 'Z axis (Yaw)')
72end
73
74if (data_to_plot == 3 || data_to_plot == 4)
75    figure
76    hold on
77    plot(t_orient, orient, '.')
78    plot(t_orient, orient)
79    hold off
80    title('Orientation')
81    legend('Yaw', 'Pitch', 'Roll')
82end
83
84
85%% Analyze Signal (Motion Detector)
86
87analyze_acc_signal = 1; % Set to 1 if I want to analyze the acceleration
88% and if filtered_value was calculated
89
90detector1 = 1; % Set to 1 is using Z axis Up/Down Motion Detector
91
92
93
94
95% Detector1 detects Z axis Up/Down Motion
96% This detector assumes:
97%   - Initial resting acceleration is know (should be 1G)
98%   - Any acceleration in X and Y is neglected
99%   - Signal is filtered using an LPF, hence the absolute acceleration
100%   values (especially the peak values) do not have meaning
101
102if analyze_acc_signal == 1 && detector1 == 1
103   
104    signal_to_analyze = filtered_value;
105    INITIALIZATION_TIME = 10;
106    WINDOW_SIZE = 10; % this value specifies the time window (in samples)
107    % used by the detector
108    % NOTE: in the final implementation, the window size may have to be
109    % specified in time and then adjusted to samples! (Because sampling
110    % rate may vary at running time)
111   
112    MAXIMUM_TRANSITION_PHASE_TIME = 15; % number of samples that transition
113    % is allowed to take
114
115    for t_sample = 1:length(t_acc)
116        if t_sample < INITIALIZATION_TIME
117            % Not enough information and filter may have distorted the
118            % signal. Hence, do nothing
119        end
120       
121        if ~phase1_detected
122            % Detect phase1. 2 Scenarios:
123            % TODO
124           
125            if detecting_phase2 % continue this
126           
127           
128           
129        else %if phase1_detected
130           
131            % If transition maximum time has expired and we still did not
132            % reach a possible phase2
133            if current_time - phase1_detection_time > MAXIMUM_TRANSITION_PHASE_TIME ...
134                    && ~detecting_phase2
135                phase1_detected = 0;
136            else
137                % 2 scenarios possible:
138                %   - transition is happening and value has not reached the
139                %   positive threshold
140                %   - transition has happened and value has already reached
141                %   the positive threshold, but phase2 has not been
142                %   confirmed yet (we are still on phase2)
143                if signal_to_analyze(t_sample) > THRESHOLD_VALUE
144                    detecting_phase2 = 1;
145                end
146                if detecting_phase2
147                    % Continue detecting phase2
148                end
149               
150            end
151           
152           
153            % Set phase1_detected to 0 if phase2 was detected or if phase2
154            % was rejected
155       
156    end
157end
158
159
160%% Clean up
161
162clear m
163connector off
Note: See TracBrowser for help on using the repository browser.