0001 function angles = GetAngles(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 global DATA SETTINGS;
0030 if isempty(DATA),
0031 error('No session defined (did you forget to call SetCurrentSession? Type ''help <a href="matlab:help Data">Data</a>'' for details).');
0032 end
0033
0034
0035 mode = 'clean';
0036
0037 if mod(length(varargin),2) ~= 0,
0038 error('Incorrect number of parameters (type ''help <a href="matlab:help GetAngles">GetAngles</a>'' for details).');
0039 end
0040
0041
0042 for i = 1:2:length(varargin),
0043 if ~ischar(varargin{i}),
0044 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help GetAngles">GetAngles</a>'' for details).']);
0045 end
0046 switch(lower(varargin{i})),
0047 case 'mode',
0048 mode = lower(varargin{i+1});
0049 if ~isastring(mode,'clean','all'),
0050 error('Incorrect value for property ''mode'' (type ''help <a href="matlab:help GetAngles">GetAngles</a>'' for details).');
0051 end
0052 otherwise,
0053 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help GetAngles">GetAngles</a>'' for details).']);
0054 end
0055 end
0056
0057 angles = [];
0058 positions = DATA.positions;
0059 if isempty(positions), return; end
0060
0061
0062 if size(positions,2) < 5,
0063 error('Insufficient number of LEDs (type ''help <a href="matlab:help GetAngles">GetAngles</a>'' for details).');
0064 end
0065
0066
0067 if strcmp(mode,'clean'),
0068 distance = sqrt((positions(:,4)-positions(:,2)).^2+(positions(:,5)-positions(:,3)).^2);
0069 selected = (distance >= SETTINGS.minDistance & distance <= SETTINGS.maxDistance);
0070 positions = positions(selected,:);
0071 end
0072
0073
0074 discard = any(positions(:,2:end) == -1,2);
0075 positions(discard,:) = [];
0076
0077
0078 m = min(positions(:,2:end));
0079 M = max(positions(:,2:end));
0080 if any(m<0)||any(M(1:2:end)>DATA.maxX|M(2:2:end)>DATA.maxY),
0081 warning(['Position data should stay within [0,' num2str(DATA.maxX) ']x[0,' num2str(DATA.maxY) ']. The data will now be clipped accordingly.']);
0082 positions(:,2) = Clip(positions(:,2),0,DATA.maxX);
0083 positions(:,3) = Clip(positions(:,3),0,DATA.maxY);
0084 end
0085
0086 positions(:,2:end) = Smooth(positions(:,2:end),[5 0]);
0087 angles(:,1) = positions(:,1);
0088 angles(:,2) = angle( positions(:,4)-positions(:,2)+j*(positions(:,5)-positions(:,3)) );