-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyo_matlab.m
70 lines (53 loc) · 1.77 KB
/
myo_matlab.m
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
%% Set up the MiniVIE path
cd('MiniVIE');
MiniVIE.configurePath;
%% Create an object for UDP interface to the Myo Armband
hMyo = Inputs.MyoUdp.getInstance();
hMyo.initialize();
%% start up the signal viewer
hViewer = GUIs.guiSignalViewer(hMyo);
% come back to this folder
cd('C:\GitHub\hrilabs\Lab4_EMGControl');
cleanup;
cd('..\..\MiniVIE')
obj = MiniVIE;
% CHANGE THIS TO MATCH YOUR TRAINING DATA FILE
myDataFilename = 'C:\Users\HRIadmin\PycharmProjects\pick_and_place\data\CH_PRJ_DATA_v2.trainingData';
% Load training data file
hData = PatternRecognition.TrainingData();
hData.loadTrainingData(myDataFilename);
% Create EMG Myo Interface Object
hMyo = Inputs.MyoUdp.getInstance();
hMyo.initialize();
% Create LDA Classifier Object
hLda = SignalAnalysis.Lda;
hLda.initialize(hData);
hLda.train();
hLda.computeError();
counter = 0;
classes = [];
udpMyo = PnetClass(5007, 5006, '127.0.0.1');
udpMyo.enableLogging = true;
udpMyo.initialize();
StartStopForm([]); % initialize a small gui utility to control a while loop
while StartStopForm
% Get the appropriate number of EMG samples for the 8 myo channels
emgData = hMyo.getData(hLda.NumSamplesPerWindow,1:8);
% Extract features and classify
features2D = hLda.extractfeatures(emgData);
[classDecision, voteDecision] = hLda.classify(reshape(features2D',[],1));
% Display the resulting class number and name
classes = [classes classDecision];
counter = counter + 1;
if counter == 5
class = mode(classes);
classNames = hLda.getClassNames;
className = classNames{class};
udpMyo.putData(uint8(class))
fprintf('Class=%2d; Class = %16s;\n',class, className);
counter = 0;
classes = [];
end
% refresh the display
drawnow;
end