**10.1. Data bases building with multiple feature parameters**

Training of the system involves the partitioning of the feature space to represent different classes of separable motions. In this state, data base is constrained with five muscles (biceps, triceps, deltoid, extensor carpi radialis and flexor carpi ulnaris). This stage has the following steps:

**Step 1.** Take six frames from each muscle as shown in Fig. 10 to produce thirty frames.

**Step 2.** Six features (which were introduced in section (4)) are extracted from each frame. In this step thirty vectors are billed as a basic Data Base, each vector has six elements. See Fig.11.

Frame 1 Frame 2 Frame 3 Frame 4 Frame 5 Frame 6

**Figure 10.** EMG Signal frames.

$$\text{DB} \rightleftharpoons \{ \text{IEMG} \mathrel{} \text{MAV} \mathrel{} \text{MMAV} \mathrel{} \text{VAR} \mathrel{} \text{VAR} \mathrel{} \text{WAMP} \text{\scriptsize} \text{WL} \}\tag{5}$$

i=1,…,30 ,j=1,…,6

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

is outlined in Fig. 9 and the stages of proposed system are discussed below:

**Figure 9.** Structure of the Recognition system based on K-NN classifier

steps:

See Fig.11.

**10.1. Data bases building with multiple feature parameters** 

Training of the system involves the partitioning of the feature space to represent different classes of separable motions. In this state, data base is constrained with five muscles (biceps, triceps, deltoid, extensor carpi radialis and flexor carpi ulnaris). This stage has the following

**Step 1.** Take six frames from each muscle as shown in Fig. 10 to produce thirty frames. **Step 2.** Six features (which were introduced in section (4)) are extracted from each frame. In this step thirty vectors are billed as a basic Data Base, each vector has six elements.

signals to a motion command perfectly.

almost entirely on the choice of features used to represent the raw signals. In the proposed system multiple feature parameters for EMG pattern classification are used since it is very difficult to extract a feature parameter which reflects the unique feature of the measured

Five kinds of arm motion are recognized: Abduction of the arm, flexion the elbow, extension the elbow, extension and abduction of the wrist and flexes and adducts the wrist .These motions are produced by contraction of five muscles. Therefore ,if the EMG signal of muscle is recognized then the specified motion of this muscle is recognized. The proposed method

**Figure 11.** Building Data Base from EMG signals

#### **10.2. Recognition of EMG signals based on k-nearest neighbor algorithm**

The data for EMG are generated by EMG simulator then processing will be applied to this signal such as feature extraction.

The recognition system of EMG patterns consists of the following steps:


$$\text{Dst} = \{ \text{Dist(DBi,IF)} \text{ i} = 1, 2, \dots, 30 \} \tag{6}$$


As illustrated above, it is necessary to find the distances between the query and all training samples and the closeness is defined in terms of Euclidean distance. Each muscle have specified motion therefore after recognize the EMG signal the command is sent to prosthetic arm to perform the motion of this muscle. The performance index for the Recognition Accuracy (RA) is given by (Momen et al.,2008):

$$RA = \frac{c\alpha}{tm} \text{x100} \tag{7}$$

Where: *co* is the number of correctly classified EMG signals.

*tn* is the total number of EMG signals.

#### **Case study:**

The simulated data are generated from an EMG signal simulator. Several motions are recognized based on classification of five input EMG signals. In the present study, the accuracy for each participant is simply calculated by averaging the performance indices over all movements. To simulate real noise, different noise is considered, i.e. random noise. The noise is added to EMG signals which produce new EMG signal with lower SNR. Now some noised EMG signals are classified using Artificial Neural Network (ANN) and k-Nearest Neighbor algorithm.

Table 3 gives the comparison results of the K-NN with different K values with the back propagation neural network (BP-NN). The structure of BP-NN is (6-20-5). Where the input nodes equal to the number of the features and output nods equal to the number of classified EMG signals.

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

The recognition system of EMG patterns consists of the following steps:

represent K-NN algorithm as shown in Fig. 12.

signal such as feature extraction.

(Dst1, Dst2,…, Dst30)

**10.2. Recognition of EMG signals based on k-nearest neighbor algorithm** 

The data for EMG are generated by EMG simulator then processing will be applied to this

**Step 3.** In this step take the feature extraction of input signal to produce Input Feature (IF) which has six elements. Now, there is one vector and it is required to be classified to which type of EMG signal included with thirty frame found in data base, step 2-6

**Step 4.** Take Euclidean distance between IF and DB to produce set of distance elements

 Dsti ={ Dist(DBi,IF) i=1,2,…,30} (6) **Step 5.** Take the nearest neighbors to IF by sorting the distance elements ascendant to

**Step 8.** Apply Majority Rule (Which EMG signals has largest number of neighbors from input signal in the K-Nearest Neighbors frames?). The input signal is assigned the most

As illustrated above, it is necessary to find the distances between the query and all training samples and the closeness is defined in terms of Euclidean distance. Each muscle have specified motion therefore after recognize the EMG signal the command is sent to prosthetic arm to perform the motion of this muscle. The performance index for the Recognition

<sup>100</sup> *co RA x*

The simulated data are generated from an EMG signal simulator. Several motions are recognized based on classification of five input EMG signals. In the present study, the accuracy for each participant is simply calculated by averaging the performance indices over all movements. To simulate real noise, different noise is considered, i.e. random noise. The noise is added to EMG signals which produce new EMG signal with lower SNR. Now some noised EMG signals are classified using Artificial Neural Network (ANN) and k-Nearest

Table 3 gives the comparison results of the K-NN with different K values with the back propagation neural network (BP-NN). The structure of BP-NN is (6-20-5). Where the input

*tn* (7)

produce sorted elements (S1,S2,…,S30), where S1 is nearest element to IF.

**Step 6.** Take the first Kth elements from sorted elements (S1,S2,…,SK). **Step 7.** Assign sorted elements to its original frames of EMG signals.

common class of EMG signal among its k nearest neighbors.

Accuracy (RA) is given by (Momen et al.,2008):

*tn* is the total number of EMG signals.

**Case study:** 

Neighbor algorithm.

Where: *co* is the number of correctly classified EMG signals.

**Figure 12.** K-NN Classification Process


**Table 3.** Recognition Accuracy of Neural Network and K-NN Method with Noisy Signal.

The MATLAB program is given below:

%%%%%%% main program of EMG recognition clear clc load mscl2 %--------------------- % test signal %------------------- interval=1600; ths=50;v=120; DB=build\_data\_base; %%%%%%%%% chose second EMG signal as test signal with added noise x=mscl2(1,:); xold=x; x = x'+v\*randn(size((x'))); r = SNR(x, xold'); %--------------------- % featur extraction %------------------- mx=mean(abs(x)); vx=var(abs(x)); mavx=mean(abs(x))/interval; w=.5\*ones(1,interval);w(1,.25\*interval:.75\*interval)=1; mmavt1=mean((w.\*abs(x'))')/interval; wwamp=WAMPsingle(x',ths); wl=Wlsingle(x'); IF=[mx vx mavx mmavt1 wwamp wl];

```
%---------------------
% apply k-nn 
%--------------------
Dst=dist(IF,DB); 
nn=6; 
[a ,b]=sort(Dst); 
st=floor(b/nn)+1; 
kk=15; 
Frame=st(1:kk)'; 
x=ones(length(Frame),1); 
a1= Frame ==1; 
b1=sum(x(a1)); 
a2= Frame ==2; 
b2=sum(x(a2)); 
a3= Frame ==3; 
b3=sum(x(a3)); 
a4= Frame ==4; 
b4=sum(x(a4)); 
a5= Frame ==5; 
b5=sum(x(a5)); 
bb=[b1 b2 b3 b4 b5]; 
[a ,b]=sort(bb); 
af=fliplr(a);bf=fliplr(b); 
result=bf(1)
```
K-NN K=9

25 83% 100% 100% 100% 100% 100%

11 66% 100% 100% 100% 100% 100%

9 66% 100% 100% 100% 100% 100%

7 66% 80% 83% 88% 90% 83%

5 50% 70% 73% 80% 83% 80%

**Table 3.** Recognition Accuracy of Neural Network and K-NN Method with Noisy Signal.

%%%%%%%%% chose second EMG signal as test signal with added noise

K-NN K=13

K-NN K=15

K-NN K=17

K=7

ANN K-NN

SNR (dB)

The MATLAB program is given below:

clear clc

load mscl2 %--------------------- % test signal %------------------- interval=1600; ths=50;v=120;

DB=build\_data\_base;

x = x'+v\*randn(size((x')));

mavx=mean(abs(x))/interval;

wwamp=WAMPsingle(x',ths);

mmavt1=mean((w.\*abs(x'))')/interval;

IF=[mx vx mavx mmavt1 wwamp wl];

w=.5\*ones(1,interval);w(1,.25\*interval:.75\*interval)=1;

x=mscl2(1,:); xold=x;

r = SNR(x, xold'); %--------------------- % featur extraction %------------------- mx=mean(abs(x)); vx=var(abs(x));

wl=Wlsingle(x');

%%%%%%% main program of EMG recognition
