diff --git a/utils/syncdata.m b/utils/syncdata.m index 5571acfc6d3f32268e7e4b948403c6e050e7af87..84243ebf52a1f7373158393e8739c5f531033f4b 100644 --- a/utils/syncdata.m +++ b/utils/syncdata.m @@ -35,8 +35,8 @@ function [arduSynced, tunnelSynced, arduStartTime, tunnelStartTime] = ... END_TRIM_SECONDS = 2; % Number of seconds to trim at the end, [s] % Detect start of wing motion in Arduino and wind tunnel datasets - [arduStartIdx, arduStartTime] = getstartardu(arduShort); - [tunnelStartIdx, tunnelStartTime] = getstarttunnel(tunnelData); + [arduStartIdx, arduStartTime, steadyIdx] = getstartardu(arduShort); + [tunnelStartIdx, tunnelStartTime] = getstarttunnel(tunnelData, steadyIdx); % Trim everything before wing starts in both datasets arduShort = arduShort(arduStartIdx:end, :); @@ -70,24 +70,30 @@ function [arduSynced, tunnelSynced, arduStartTime, tunnelStartTime] = ... end -function [startIdx, startTime] = getstartardu(arduData) +function [startIdx, startTime, steadyIdx] = getstartardu(arduData) % GETSTARTARDU Get the starting po int for the arduino dataset and the flapping direction at % start ANGLE_IDX = [2, 3]; % Indexes of the front and aft angles in arduData file N_STABLE_VAL = 20; % Number of stable values before beginnig of motion DCRIT = 0.1; % Deviation from the mean to be considered a "large" deviation + STD_NO_MOTION = 3; % A standard deviation less than 1deg means no motion % Get a first approximation for the starting point of each wing set startIdx = [NaN, NaN]; + steadyIdx = [NaN, NaN]; for i = 1:2 - startIdx(i) = findsignalstart(arduData(:, ANGLE_IDX(i)), N_STABLE_VAL, 'ardu', DCRIT); + if std(arduData(:, ANGLE_IDX(i))) > STD_NO_MOTION + startIdx(i) = findsignalstart(arduData(:, ANGLE_IDX(i)), N_STABLE_VAL, 'ardu', DCRIT); + else + steadyIdx(i) = i; + end end startIdx = min(startIdx); startTime = arduData(startIdx, 1); end -function [startIdx, startTime] = getstarttunnel(tunnelData) +function [startIdx, startTime] = getstarttunnel(tunnelData, steadyIdx) % GETSTARTTUNNEL Get the starting point for the wind tunnel dataset % Only use the Fz to determine starting point @@ -101,7 +107,9 @@ function [startIdx, startTime] = getstarttunnel(tunnelData) startIdx = [NaN, NaN]; for i = 1:2 - startIdx(i) = findsignalstart(tunnelData(:, FZ_IDX(i)), SAMPLING / 2, 'tunnel', DCRIT); + if steadyIdx(i) ~= i + startIdx(i) = findsignalstart(tunnelData(:, FZ_IDX(i)), SAMPLING / 2, 'tunnel', DCRIT); + end end startIdx = TRIM_MS + min(startIdx); startTime = startIdx / SAMPLING;