-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculateAmplitudes.asv
74 lines (71 loc) · 3.47 KB
/
CalculateAmplitudes.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function Data = ...
CalculateAmplitudes(Data, AmplitudeThreshold, TimeThreshold, SamplingRate)
% CalculateAmplitudes calculates the amplitude of transients from movement
% data. Transients that are too small (less than AmplitudeThreshold) or
% too short (less than TimeThreshold) are discarded.
TimeThresholdInTimepoints = TimeThreshold * SamplingRate / 1000;
for i = 1:length(Data)
XAmplitude = CalculateAndTrimAmplitudes(Data(i).XPosition, ...
AmplitudeThreshold, TimeThresholdInTimepoints);
YAmplitude = CalculateAndTrimAmplitudes(Data(i).YPosition, ...
AmplitudeThreshold, TimeThresholdInTimepoints);
ZAmplitude = CalculateAndTrimAmplitudes(Data(i).ZPosition, ...
AmplitudeThreshold, TimeThresholdInTimepoints);
% XReversals = (Data(i).XPosition - circshift(Data(i).XPosition', 1)') .* ...
% ( Data(i).XPosition - circshift(Data(i).XPosition', -1)');
% XReversalsIndices = PositionIndices(XReversals > 0 );
% % discard transients that are too short
% XTransientLengthsInTimepoints = ...
% XReversalsIndices - circshift(XReversalsIndices', 1)';
% XReversalsIndices( ...
% XTransientLengthsInTimepoints < TimeThresholdInTimepoints ) = [];
% for j = 2:length(XReversalsIndices)
% XAmplitude(j-1) = abs(Data(i).XPosition(XReversalsIndices(j)) - ...
% Data(i).XPosition(XReversalsIndices(j - 1) ));
% end
% %discard transients that are too small
% XAmplitude( XAmplitude < AmplitudeThreshold ) = [];
%
% YReversals = (Data(i).YPosition - circshift(Data(i).YPosition', 1)') .* ...
% ( Data(i).YPosition - circshift(Data(i).YPosition', -1)');
% YReversalsIndices = PositionIndices(YReversals > 0 );
% YTransientLengthsInTimepoints = ...
% YReversalsIndices - circshift(YReversalsIndices', 1)';
% XReversalsIndices( ...
% XTransientLengthsInTimepoints < TimeThresholdInTimepoints ) = [];
% for j = 2:length(YReversalsIndices)
% YAmplitude(j-1) = abs(Data(i).YPosition(YReversalsIndices(j)) - ...
% Data(i).YPosition(YReversalsIndices(j - 1) ));
% end
%
% ZReversals = (Data(i).ZPosition - circshift(Data(i).ZPosition', 1)') .* ...
% ( Data(i).ZPosition - circshift(Data(i).ZPosition', -1)');
% ZReversalsIndices = PositionIndices(ZReversals > 0 );
% for j = 2:length(ZReversalsIndices)
% ZAmplitude(j-1) = abs(Data(i).ZPosition(ZReversalsIndices(j)) - ...
% Data(i).ZPosition(ZReversalsIndices(j - 1) ));
% end
%
Data(i).XAmplitude = XAmplitude;
Data(i).YAmplitude = YAmplitude;
Data(i).ZAmplitude = ZAmplitude;
end
end
function AmplitudeVector = CalculateAndTrimAmplitudes(PositionVector, ...
AmplitudeThreshold, TimeThresholdInTimepoints)
PositionIndices = 1:length( PositionVector );
Reversals = (PositionVector - circshift(PositionVector', 1)') .* ...
( PositionVector - circshift(PositionVector', -1)');
ReversalsIndices = PositionIndices(Reversals > 0 );
% discard transients that are too short
TransientLengthsInTimepoints = ...
ReversalsIndices - circshift(ReversalsIndices', 1)';
ReversalsIndices( ...
TransientLengthsInTimepoints < TimeThresholdInTimepoints ) = [];
for j = 2:length(ReversalsIndices)
AmplitudeVector(j-1) = abs(PositionVector(ReversalsIndices(j)) - ...
PositionVector(ReversalsIndices(j - 1) ));
end
%discard transients that are too small
AmplitudeVector( AmplitudeVector < AmplitudeThreshold ) = [];
end