Home > data-import > run_big_moving_event_detection.m

run_big_moving_event_detection

PURPOSE ^

SYNOPSIS ^

function [ ] = run_big_moving_event_detection( sid, frequency, sensors, sensor_data )

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [ ] = run_big_moving_event_detection( sid, frequency, sensors, sensor_data )
0002 
0003 
0004     if nargin < 1 || isempty(sid)
0005        error('you must provide parameter sid as subject ID or list of subject ID'); 
0006     end
0007     
0008     if nargin < 2 || isempty(frequency)
0009         frequency = 60;
0010     end
0011     
0012     params_rot.thresh_lo = 24;%3
0013     params_rot.thresh_hi = 65; %8
0014     params_rot.fixation_creep = 16;%2
0015     params_rot.min_fixation = 0.5;
0016     params_rot.fixation_filter = 0.1; %sec
0017     params_rot.moving_filter = 0.1;      % sec
0018 
0019     factor = 25.4; %inches to mm
0020     params_pos.thresh_lo = 3*factor;
0021     params_pos.thresh_hi = 8*factor;
0022     params_pos.fixation_creep = 2*factor;
0023     params_pos.min_fixation = 0.5;
0024     params_pos.fixation_filter = 0.1; %sec
0025     params_pos.moving_filter = 0.1;      % sec
0026     
0027     if numel(sid) > 1
0028         %a list of subject ID
0029         for i = 1 : numel(sid)
0030             run_big_moving_event_detection(sid(i), frequency);
0031         end
0032         return
0033     end
0034 
0035     %read and resample the sensor data of all sensors.
0036     if ~exist('sensor_data', 'var') || isempty(sensor_data)
0037         try
0038             [s_pos, s_rot] = read_pos_sensor(sid, [ ], frequency);
0039         catch ME
0040             disp(ME);
0041             return;
0042         end
0043     else
0044         s_pos = sensor_data{1};
0045         s_rot = sensor_data{2};
0046     end
0047     
0048     max_sensor_id = numel( s_pos );
0049     sensor_list = 1:max_sensor_id;
0050     valid_sensor_list = [];
0051 
0052     %--select sensors with data and pair for hand-------------------------
0053     for sensor_id = sensor_list
0054         if ~isempty(s_pos{sensor_id})
0055             valid_sensor_list = [valid_sensor_list sensor_id];
0056         end
0057     end
0058     sensor_list = valid_sensor_list;
0059     
0060     if exist('sensors', 'var') && ~isempty(sensors)
0061         sensor_list = sensor_list(ismember(sensors, sensor_list));
0062     end
0063 
0064     %to ensure both hands are there. not sure why this is here -sbf
0065 %     if (~ismember(3, sensor_list)) || (~ismember(4, sensor_list))
0066 %         sensor_list = setdiff(sensor_list, [3 4]);
0067 %     end
0068 %     if (~ismember(5, sensor_list)) || (~ismember(6, sensor_list))
0069 %         sensor_list = setdiff(sensor_list, [5 6]);
0070 %     end
0071     %-------------------------------------------------------------------
0072     
0073     pos_movements = cell(numel( s_pos ), 1);
0074     rot_movements = cell( numel( s_rot ), 1);
0075     for sensor_index = 1 : numel(sensor_list)
0076         sensor_id = sensor_list(sensor_index);
0077         if sensor_id <= 2 
0078             %head sensor, use the default parameters
0079         else
0080             %hand sensor, we should find a suitable parameters
0081             params_rot.thresh_lo = 120.0;
0082             params_rot.thresh_hi = 180.0;
0083             params_rot.fixation_creep = 15;
0084 
0085             params_pos.thresh_lo = 9*factor;
0086             params_pos.thresh_hi = 12*factor;
0087             params_pos.fixation_creep = 2*factor;
0088             %break; %now we produce moving event for head only.
0089         end
0090         
0091 %         pos_mvmt = detect_movement(s_pos{sensor_id}, params_pos);
0092 %         pos_movements{sensor_id} = cevent2event(cevent_category_equals(pos_mvmt, [2 3]));
0093 %
0094 %         rot_mvmt = detect_movement(s_rot{sensor_id}, params_rot);
0095 %         rot_movements{sensor_id} = cevent2event(cevent_category_equals(rot_mvmt, [2 3]));
0096         pos_movements{sensor_id} = detect_moving_event(s_pos{sensor_id}, params_pos);
0097         rot_movements{sensor_id} = detect_moving_event(s_rot{sensor_id}, params_rot);
0098     end
0099     
0100     %to save moving event to file
0101     save_path ='';% 'ywz/'; %save into a temp directory for test only, so we can compare variables
0102     for sensor_index = 1 : numel(sensor_list) 
0103         sensor_id = sensor_list(sensor_index);
0104         sensor_name = get_sensor_name( sensor_id ); %head_child, head_parent, ...
0105         if isempty(sensor_name)
0106             disp(['senor ' num2str(sensor_id) ' may be wrong']);
0107             continue;
0108         end
0109         variable_name_suffix = regexprep(sensor_name, '_', '_big-moving_');
0110         
0111         %record position moving event
0112         variable_name = [save_path 'event_motion_pos_' variable_name_suffix];
0113         record_variable(sid, variable_name, pos_movements{sensor_id} );
0114         
0115         %record orientation moving event
0116         variable_name = [save_path 'event_motion_rot_' variable_name_suffix];
0117         record_variable(sid, variable_name, rot_movements{sensor_id} );
0118     end
0119     disp('Done with movement detection');
0120 end
0121 
0122 %%
0123 function [ result ] = get_sensor_name( sensor_id )
0124     sensor_names = { 'head_child', 'head_parent', ...
0125                      'left-hand_child', 'right-hand_child', ...
0126                      'left-hand_parent', 'right-hand_parent' };
0127     if sensor_id <1 || sensor_id > numel(sensor_names)
0128         result =[];
0129     else
0130         result = sensor_names{ sensor_id };
0131     end
0132 end
0133 
0134

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005