**7. Measurement of Real EMG signal**

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

%%%% main program of KNN Dst=dist(IF,DB);nn=6;[a ,b]=sort(Dst);

kk=15;y=st(1:kk)';x=ones(length(y),1);

[a ,b]=sort(bb);af=fliplr(a);bf=fliplr(b);

Start

Compute the distance between input sample and the training samples

Initialization, define *K*

Sort the distance

Take K nearest neighbors

Apply simple majority

End

st=floor(b/nn)+1;

result=bf(1)

a1= y ==1;b1=sum(x(a1)); a2= y ==2;b2=sum(x(a2)); a3= y ==3;b3=sum(x(a3)); a4= y ==4;b4=sum(x(a4)); a5= y ==5;b5=sum(x(a5)); bb=[b1 b2 b3 b4 b5];

The MATLAB program of K-NN is :

**Figure 4.** Flowchart for the K- nearest neighbors

EMG signal has two main sources, one of them is measured real EMG and the other one is generated EMG by EMG Simulator. Every one of them has advantage and disadvantage with respect to accuracy and reliability. There are many problems in real measurement system as follows: The first stage is the sensor of EMG signal (electrodes), there are two problems related with the considered structure. The first problem related with the electrode types, that is a needle type. This problem can be summarized as follows: the procedure for using this type by inserting the needle in proper placement on muscle to touch the fiber and sensing the EMG signal. One disadvantage of this needle type is caused high pain to human and it has side affect if using for long times, and it is used only with up normal muscle to check the activity or response of nerve that supply this muscle. Another problem is fixing the needle on the skin, where at any movement of muscle the needle will go out. To overcome the above mentioned problems, the needle may be replaced by either surface electrode or integral surface electrode. The main advantage for using the needle electrode is the amplitude of measured signal where it is better than using another types. In the needle case, the EMG signal is measured directly from MU. The second problem of obtaining EMG signals measured by a needle is only one channel exist for measuring in the same time. This is huge problem in the design where it needs number of channels equal to number of muscles that caused the required recognized movements. If one likes to recognize the wrist joint movement he needs four channels. To overcome the problems in real measuring system, the user can use the generation of EMG signal by EMG simulator*.*
