cont_speed calculates the speed based on a continuous position. USAGE: cont_speed(POSITION) The input can have more than one dimension of position: [t1 x1] or [t1 x1 y1] or [t1 x1 y1 z1] or whatever. In the output, the value at time T is the speed in the interval leading up to time T. This function takes into account the time interval between subsequent samples, it's not just the derivative of the values. A division by 0 will result if subsequent samples have the same time stamp, remove those cases before passing data to this function. The speed for the first sample is defined to equal the speed for the second sample, just so there's a value there.

- distances distances calculates the distance between each pair of vectors.

- run_position_speed Imports the sensor data. Resample the data with frequency and
- detect_movement Detect_movement examines position data to return a cevent
- detect_moving_event Detect_moving_event examines position data to return a cevent

0001 function time_speed = cont_speed(position) 0002 % cont_speed calculates the speed based on a continuous position. 0003 % 0004 % USAGE: 0005 % cont_speed(POSITION) 0006 % 0007 % The input can have more than one dimension of position: [t1 x1] or [t1 0008 % x1 y1] or [t1 x1 y1 z1] or whatever. 0009 % 0010 % In the output, the value at time T is the speed in the interval leading 0011 % up to time T. 0012 % 0013 % This function takes into account the time interval between subsequent 0014 % samples, it's not just the derivative of the values. A division by 0 0015 % will result if subsequent samples have the same time stamp, remove 0016 % those cases before passing data to this function. 0017 % 0018 % The speed for the first sample is defined to equal the speed for the 0019 % second sample, just so there's a value there. 0020 0021 [missing_last missing_first] = offset_pair(position); 0022 0023 dists = distances(missing_last(:, 2:end), missing_first(:, 2:end)); 0024 0025 timedists = distances(missing_last(:, 1), missing_first(:, 1)); 0026 0027 speed = dists ./ timedists; 0028 0029 speed = [speed(1); speed]; 0030 0031 time_speed = horzcat(position(:, 1), speed); 0032 0033 0034 0035 0036 function [missing_last missing_first] = offset_pair(A) 0037 % offset_pair makes a pair of matrices, used for calculating derivative 0038 % 0039 % The first matrix is missing the last row of the input, and the second 0040 % matrix is missing the first row of the input. That means that they have 0041 % the same number of rows, and each row in the pair can be compared to see 0042 % the difference between subsequent rows in the input matrix. 0043 0044 missing_last = A(1:end-1, :); 0045 missing_first = A(2:end, :); 0046 0047 0048 function distances = distances(A, B) 0049 % distances calculates the distance between each pair of vectors. 0050 % 0051 % Usage: 0052 % distances(A, B) 0053 % For each row in A, takes the corresponding row in B, and calculates the 0054 % Euclidean distance between the two vectors represented by the rows. A 0055 % and B should have the same dimensions. 0056 % 0057 % This is performed in a vectorized way, so it should be quite fast. 0058 % 0059 0060 0061 D = A - B; 0062 distances = sqrt(sum(D.*D, 2));

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