How do I cut my EMG signal and get an average signal?

826 Views Asked by At

I have an EMG signal of a subject walking on a treadmill. We used footswitches to be able to see when the subject is placing his foot, so we can see how many periods (steps) there are in time. We would like to cut the signal in periods (steps) and get one average signal (100% step cycle).

I tried the reshape function but it does not work

when I count 38 steps:

nwaves = 38;
sig2 = reshape(sig,[numel(sig)/nwaves nwaves])';
avgSig = mean(sig2,1);
plot(avgSig);

the error displayed is this: Size arguments must be real integers.

Can anyone help me with this? Thanks!

2

There are 2 best solutions below

2
On BEST ANSWER

First of all, reshaping the array is a bad approach to the problem. In real world one cannot assume that the person on the treadmill will step rhythmically with millisecond-precision (i.e. for the same amount of samples).

A more realistic approach is to use the footswitch signal: assume is really a switch on a single foot (1=foot on, 0=foot off), and its actions are filtered to avoid noise (Schmidt trigger, for example), you can get the samples index when the foot is removed from the treadmill with:

foot_off = find(diff(footswitch) < 0);

then you can transform your signal in a cell array (variable lengths) of vectors of data between consecutive steps:

step_len = diff([0, foot_off, numel(footswitch)]);
sig2     = mat2cell(sig(:), step_len, 1);

The problem now is you can't apply mean() to the signal slices in order to get an "average step": you must process each step first, then average the results.

6
On

It's probably because numel(sig)/nwaves isn't an integer. You need to round it to the nearest integer with round(numel(sig)/nwaves).

EDIT based on comments:

Your problem is you can't divide 51116 by 38 (it's 1345.2), so you can't reshape your signal in chunks of 38 long. You need a signal whose length is exactly a multiple of 38 if you want to be able to reshape it in chunks of 38. Either that, or remove the last (or first) 6 values from your signal to have an exact multiple of 38 (1345 * 38 = 51110):

nwaves = 38;
n_chunks = round(numel(sig)/nwaves);
max_sig_length =  n_chunks * nwaves;
sig2 = reshape(sig(1:max_sig_length),[n_chunks nwaves])';
avgSig = mean(sig2,1);
plot(avgSig);