Neural network to control prosthesis

3 views (last 30 days)
Hey guys , I'm a student of biomedical engineering, and i need some help.
I'm doing a project that controls a prothesis simulated in Unity by EMG signals.
First , to train the network , I have collected 30 EMG signals , with two channels (biceps and triceps) ,from 7 moviments. then i need to use a neuralnetwork with backpropagation to determinate what moviment the person is doing in real time.
From each signal i have calculated 10 features , 5 from each signal. they are : Mean Absolute Value , Mean Absolute Value Slope , Zero Crossing , Slope Sign Changes and Waveform Length.
So , my features vector to be the input in the training is the attached file 'caracteristicas.mat'.
My network output will be size 7, each being a moviment, and my input will be size 10 . i tryed to train the network using 20 of the 30 signals, and use the others 10 to test the simulation . I made this code :
clear all
close all
clc
load('../caracteristicas.mat');
indice = [1,20;31,50;61,80;91,110;121,140;151,170;181,200];
T = [1,0,0,0,0,0,0;0,1,0,0,0,0,0;0,0,1,0,0,0,0;0,0,0,1,0,0,0;0,0,0,0,1,0,0;0,0,0,0,0,1,0;0,0,0,0,0,0,1;];
net = newff([min(carac')' max(carac')'],[10 8 7],{'tansig' 'purelin' 'logsig'},'traingd');
net.trainParam.epochs = 100;
for i = 1:7
net = train(net,carac(indice(i,1):indice(i,2),:),T(i,:));
end
a = sim(net,carac(21,:))
Any one knows what I'm doing wrong ?
I get the following error : " Error using network/train (line 340) Inputs and targets have different numbers of samples.
Error in rede (line 10) net = train(net,carac(indice(i,1):indice(i,2),:),T(i,:)); "
How can i use the backpropagation in this code ? Can anyone help me?

Accepted Answer

Greg Heath
Greg Heath on 30 Jun 2015
What is Unity?
There is no attached code.
"indice" is undefined
30 dual channel signals
5 features per channel
7 movement classes
[ I N ] = size(input) % [10 30
[ O N ] = size(target) % [7 30]
Target columns are unit vectors from eye(7). The relationship between the true class indices (1:7) and the target matrix is
classindices = vec2ind(target)
target = ind2vec(truclassindices)
For classification use either PATTERNNET (current) or NEWPR (obsolete but still available)
Specialized PATTERNNET automatically calls generic FEEDFORWARDNET
Specialized NEWPR automatically calls generic NEWFF
The documentation and trivial example for each can be obtained using the help and doc commands, e.g.;
help patternnet
doc patternnet
Only need 1 hidden layer with H hidden nodes (I-H-O topology).
Either
net = patternnet; % default H = 10
or
net = patternnet(H);
Initially, accept all defaults.
rng(4151941) % Initialize RNG for reproducibility
[ net tr output Rerror ] = train(net, input,target);
% output = net(input);
% Rerror = target-output; %Regression errror
assignedindices = vec2ind(output);
Cerror = assigned indices~=truclassindicess; % { 0,1 } classification errors
Nerr = sum(Cerror)
PctErr = 100*Nerr/N
To find individual errors for each member of the training, validation and test subsets, use the indices found in the training record
tr = tr % No semicolon: to see what goodies tumble out!
Searching the NEWSGROUP and ANSWERS using
greg patternnet
should yield examples.
Hope this helps.
Thank you for formally accepting my answer
Greg

More Answers (0)

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!