**12. EMG simulator based GUI**

The method of recognition based K-NN algorithm and technique of virtual reality are introduced, now the simulation which connect between the EMG recognition system and virtual reality is presented.

From MATLAB, the user can set the positions and properties of VRML objects, create callbacks from Graphical User Interfaces (GUI), and map data to virtual objects. The user can also view the world with a VRML viewer, determine its structure, and assign new values to all available nodes and their fields. The Virtual Reality Toolbox includes functions for retrieving and changing the virtual world properties and for saving the VRML files corresponding to the actual structure of a virtual world. MATLAB provides communication for control and manipulation of virtual reality objects using MATLAB objects.

This part concerns with the simulation of human arm movement using EMG Signal as shown in the fig 14 .

**Figure 14.** Recognition Result Windows

It has the following stages:

384 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

**Figure 13.** The VRML model of the Human arm

%% control of human arm as MATLAB code world=vrworld('HumanArm.wrl', 'new');

elbow=vrnode(world, 'elbow');

elbow.rotation=[0 0 theta theta];

for theta=pi/2:-pi/100:0

The MATLAB program is given as:

open(world); fig=vrfigure(world);

k=0;

end

 k=k+1; x(k)=theta; pause(0.05)

**12. EMG simulator based GUI** 

vrdrawnow;

virtual reality is presented.

The method of recognition based K-NN algorithm and technique of virtual reality are introduced, now the simulation which connect between the EMG recognition system and


The recognition algorithm consists of following steps. Firstly, a nearest neighbor algorithm is applied to compute the distance between the feature extraction of input motion to be recognized and each of the 30 feature extraction representing the recognizable motions, which were collected in a Data Base. The algorithm then sorts the motion indexes starting from the nearest candidate in descending order. The distance between two patterns is computed in the feature extraction as the Euclidean distance between the two vectors of feature extraction.

The basic motions types are executed to test the model's performance: a Abduction of the arm, flexion the elbow, extension the elbow, extension and abduction of the wrist and flexes and adducts the wrist. For all motions, the system will receive an EMG signal of human arm.The MATLAB program, which executes this algorithm, is given as:

```
function EMGGUI(hObject,eventdata) 
 fh2 = figure('MenuBar','none','Name',' Artificial Human Arm Driven by EMG Signal
','NumberTitle','off','Position',[0 0 1300 800]); 
 v1=10; 
v2=20; 
v3=30; 
v4=200; 
ph = uipanel('Parent',fh2,'Position',[.65 .05 .3 .9]); 
e1 = uicontrol(fh2,'style','text','string','EMG Part','Position',[875 625 250 
75],'FontName','Century Schoolbook','FontSize',24); 
database = uicontrol(fh2,'style','pushbutton','string','Build Data Base 
','BackgroundColor','c','Position', [850 600 260 50],'callback',@Data_Base,'FontName','Century 
Schoolbook','FontSize',14); 
 e2 = uicontrol(fh2,'style','text','string','Select Test EMG Signal ','Position',[850 500 250 
60],'FontName','Century Schoolbook','FontSize',14); 
 XX7=480; 
e3 = uicontrol(fh2,'style','text','string','Biceps','Position', [850 XX7 50 
25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10); 
e4 = uicontrol(fh2,'style','pushbutton','string','Bi1','Position', [900 XX7 25 
25],'callback',@Biceps1); 
e5 = uicontrol(fh2,'style','pushbutton','string','Bi2','Position', [925 XX7 25 
25],'callback',@Biceps2);
```
e6 = uicontrol(fh2,'style','pushbutton','string','Bi3','Position', [950 XX7 25 25],'callback',@Biceps3); e7 = uicontrol(fh2,'style','pushbutton','string','Bi4','Position', [975 XX7 25 25],'callback',@Biceps4); XX1=XX7-30; e8 = uicontrol(fh2,'style','text','string','Triceps','Position', [850 XX1 50 25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10); e9 = uicontrol(fh2,'style','pushbutton','string','Tr1','Position', [900 XX1 25 25],'callback',@Triceps1); e10 = uicontrol(fh2,'style','pushbutton','string','Tr2','Position', [925 XX1 25 25],'callback',@Triceps2); e11 = uicontrol(fh2,'style','pushbutton','string','Tr3','Position', [950 XX1 25 25],'callback',@Triceps3); e12 = uicontrol(fh2,'style','pushbutton','string','Tr4','Position', [975 XX1 25 25],'callback',@Triceps4); XX2=XX1-30; e13 = uicontrol(fh2,'style','text','string','Deltoid','Position', [850 XX2 50 25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10); e14 = uicontrol(fh2,'style','pushbutton','string','De1','Position', [900 XX2 25 25],'callback',@Deltoid1); e15 = uicontrol(fh2,'style','pushbutton','string','De2','Position', [925 XX2 25 25],'callback',@Deltoid2); e16 = uicontrol(fh2,'style','pushbutton','string','De3','Position', [950 XX2 25 25],'callback',@Deltoid3); e17 = uicontrol(fh2,'style','pushbutton','string','De4','Position', [975 XX2 25 25],'callback',@Deltoid4); XX3=XX2-30; e18 = uicontrol(fh2,'style','text','string','ECR','Position', [850 XX3 50 25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10); e19 = uicontrol(fh2,'style','pushbutton','string','ECR1','Position', [900 XX3 30 25],'callback',@ECR1); e20 = uicontrol(fh2,'style','pushbutton','string','ECR2','Position', [930 XX3 30 25],'callback',@ECR2); e21 = uicontrol(fh2,'style','pushbutton','string','ECR3','Position', [960 XX3 30 25],'callback',@ECR3); e22 = uicontrol(fh2,'style','pushbutton','string','ECR4','Position', [990 XX3 30 25],'callback',@ECR4); XX4=XX3-30; e23 = uicontrol(fh2,'style','text','string','FCU','Position', [850 XX4 50 25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10);

e24 = uicontrol(fh2,'style','pushbutton','string','FCU1','Position', [900 XX4 30

25],'callback',@FCU1);

386 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

The details of this stage can be found in subsection (10.2).

selecting the muscles which produce this motion.

virtual reality.

feature extraction.

 v1=10; v2=20; v3=30; v4=200;

XX7=480;

function EMGGUI(hObject,eventdata)

Schoolbook','FontSize',14);

25],'callback',@Biceps1);

25],'callback',@Biceps2);

','NumberTitle','off','Position',[0 0 1300 800]);

ph = uipanel('Parent',fh2,'Position',[.65 .05 .3 .9]);

75],'FontName','Century Schoolbook','FontSize',24);

60],'FontName','Century Schoolbook','FontSize',14);

8. **Recognition Result:** In this stat the K-NN algorithm is applied to recognize the EMG signal in order to produce the motion provided by this EMG signal in virtual reality.

9. **Simulate Arbitrary Motion:** In this part of simulation any motion can be chosen by

10. **Simulate the Motion:** After pressing on this button the human arm is moves in the

The recognition algorithm consists of following steps. Firstly, a nearest neighbor algorithm is applied to compute the distance between the feature extraction of input motion to be recognized and each of the 30 feature extraction representing the recognizable motions, which were collected in a Data Base. The algorithm then sorts the motion indexes starting from the nearest candidate in descending order. The distance between two patterns is computed in the feature extraction as the Euclidean distance between the two vectors of

The basic motions types are executed to test the model's performance: a Abduction of the arm, flexion the elbow, extension the elbow, extension and abduction of the wrist and flexes and adducts the wrist. For all motions, the system will receive an EMG signal of human

','BackgroundColor','c','Position', [850 600 260 50],'callback',@Data\_Base,'FontName','Century

e2 = uicontrol(fh2,'style','text','string','Select Test EMG Signal ','Position',[850 500 250

arm.The MATLAB program, which executes this algorithm, is given as:

e1 = uicontrol(fh2,'style','text','string','EMG Part','Position',[875 625 250

database = uicontrol(fh2,'style','pushbutton','string','Build Data Base

e3 = uicontrol(fh2,'style','text','string','Biceps','Position', [850 XX7 50 25],'BackgroundColor','Y','FontName','Century Schoolbook','FontSize',10); e4 = uicontrol(fh2,'style','pushbutton','string','Bi1','Position', [900 XX7 25

e5 = uicontrol(fh2,'style','pushbutton','string','Bi2','Position', [925 XX7 25

fh2 = figure('MenuBar','none','Name',' Artificial Human Arm Driven by EMG Signal

e25 = uicontrol(fh2,'style','pushbutton','string','FCU2','Position', [930 XX4 30 25],'callback',@FCU2); e26 = uicontrol(fh2,'style','pushbutton','string','FCU3','Position', [960 XX4 30 25],'callback',@FCU3); e27 = uicontrol(fh2,'style','pushbutton','string','FCU4','Position', [990 XX4 30 25],'callback',@FCU4); result1 = uicontrol(fh2,'style','pushbutton','string','Recognition Result ','BackgroundColor','c','callback',@test,'Position',[850 300 270 60],'FontName','Century Schoolbook','FontSize',14); result2 = uicontrol(fh2,'style','edit','Position',[850 250 250 50],'FontName','Century Schoolbook','FontSize',14,'BackgroundColor','W'); e28 = uicontrol(fh2,'style','text','string','Simulate Arbitary Motion ','BackgroundColor','y','Position',[850 200 250 40],'FontName','Century Schoolbook','FontSize',14); e29 = uicontrol(fh2,'Style','listbox','String',{'Deltoid','Biceps','Triceps','Extensor Carpi Radialis','Flexor Carpi Ulnaris'},'Max',5,'Min',0,'Value',[1],'Position',[850 125 150 70]); e30 = uicontrol(fh2,'style','pushbutton','string','Simulate the Motion ','callback',@simulat\_motion,'BackgroundColor','c','Position',[1000 125 200 50],'FontName','Century Schoolbook','FontSize',14); end

After execution of this program, its results will be given as in Fig. 14 .

As an examples the progress of the Abduction of the arm can be observed in Fig. 15.

(0.3 sec) (0.5 sec) (0 sec) (0.1 sec)

**Figure 15.** Abduction of the arm movements

The execution of the elbow flexion can be observed in Fig. 16 along with several of the arm states. At the initial position, the human arm is in extension. When flexion begins, the human arm opposition angle is controlled to the right position for the elbow flexion. After receiving the elbow flexion signal, the structure of the arm causes its joints to flex in a natural motion

The block diagram of the package for the human arm simulator is shown in Fig. 17. It enables testing of different control algorithms. The simulator uses MATLAB as this language both provides a virtual reality toolbox and an extensive mathematical library.

388 MATLAB – A Fundamental Tool for Scientific Computing and Engineering Applications – Volume 1

e25 = uicontrol(fh2,'style','pushbutton','string','FCU2','Position', [930 XX4 30

e26 = uicontrol(fh2,'style','pushbutton','string','FCU3','Position', [960 XX4 30

e27 = uicontrol(fh2,'style','pushbutton','string','FCU4','Position', [990 XX4 30

','BackgroundColor','c','callback',@test,'Position',[850 300 270 60],'FontName','Century

result2 = uicontrol(fh2,'style','edit','Position',[850 250 250 50],'FontName','Century

e29 = uicontrol(fh2,'Style','listbox','String',{'Deltoid','Biceps','Triceps','Extensor Carpi Radialis','Flexor Carpi Ulnaris'},'Max',5,'Min',0,'Value',[1],'Position',[850 125 150 70]);

As an examples the progress of the Abduction of the arm can be observed in Fig. 15.

(0.3 sec) (0.5 sec) (0 sec) (0.1 sec)

result1 = uicontrol(fh2,'style','pushbutton','string','Recognition Result

e28 = uicontrol(fh2,'style','text','string','Simulate Arbitary Motion ','BackgroundColor','y','Position',[850 200 250 40],'FontName','Century

e30 = uicontrol(fh2,'style','pushbutton','string','Simulate the Motion ','callback',@simulat\_motion,'BackgroundColor','c','Position',[1000 125 200

After execution of this program, its results will be given as in Fig. 14 .

Schoolbook','FontSize',14,'BackgroundColor','W');

50],'FontName','Century Schoolbook','FontSize',14);

**Figure 15.** Abduction of the arm movements

25],'callback',@FCU2);

25],'callback',@FCU3);

25],'callback',@FCU4);

Schoolbook','FontSize',14);

Schoolbook','FontSize',14);

end

(0.3 sec) (0.5 sec) (0 sec) (0.1 sec)

**Figure 16.** Flexion of the elbow movements.

**Figure 17.** Block diagram for Human Arm Movement based EMG signal
