PDA

View Full Version : MatLab Code for Post-Processing EMG Data

murbin
07-27-2011, 10:20 AM
I am looking to see whether anyone has used Matlab for facilitating the post-processing of EMG data (i.e., filtering, rectification, etc.).

cscholes57
07-28-2011, 04:50 AM
I am looking to see whether anyone has used Matlab for facilitating the post-processing of EMG data (i.e., filtering, rectification, etc.).

Yep, what specifically are you looking to do?

rmiller
07-28-2011, 10:11 AM
Hi Mike,

Assuming you have Matlab itself, the help file has some pretty good examples on designing digital filters (lowpass Butterworth, bandpass) that can be easily adapted to EMG processing. The commands you probably want are "butter" (outputs Butterworth parameters) and "filtfilt" (takes these parameters and runs a recursive filter on the input signal).

To rectify (full-wave rectification) you just take the absolute value of the EMG (so in Matlab, "Rectified_EMG = abs(Original_EMG);").

Ross

whassani
07-29-2011, 08:38 AM
Hi,

If you are using an off-line treatment you can also use a zero-lag filter, you can design'it as follow:

Fe=1000; %Samling frequenc
Fc=3; % Cut-off frequency (from 2 Hz to 6 Hz depending to the type of your electrod)
N=4; % Filter Order
[B, A] = butter(N,Fc*2/Fe, 'low'); %filter's parameters
EMG=filtfilt(B, A, Rectified_EMG); %in the case of Off-line treatment

if your are using an on-line treatment use this

Fe=1000; %Samling frequency in Hz
Fc=3; % Cut-off frequency (from 2 Hz to 6 Hz depending to the type of your electrod)
N=4; % Filter Order
[B, A] = butter(N,Fc*2/Fe, 'low'); %filter's parameters
EMG=filter(B,A, Rectified_EMG); %in the case of real-time treatment

Don't forgot, before the filtering you must rectify the EMG signal as specified by Ross you can use ("Rectified_EMG = abs(Original_EMG);) this step is necessary, after this step you can also use High-Pass filter for eleminating the artefacts in the signal du the movement when recording the EMG. After that, you smooth your EMG signal as mentionned adove.

Take car your, the cut-off frequency is very important!!!!

regards,

Walid

smiller45
07-30-2011, 03:38 AM
Don't forgot, before the filtering you must rectify the EMG signal as specified by Ross you can use ("Rectified_EMG = abs(Original_EMG);) this step is necessary, after this step you can also use High-Pass filter for eleminating the artefacts in the signal du the movement when recording the EMG. After that, you smooth your EMG signal as mentionned adove.

Take car your, the cut-off frequency is very important
Walid

Hi Walid,

Good post on the MatLab filtering. The last part got me thinking. Do you high pass filter your data after the full wave rectification? I have always performed this before the rectification, and I haven't read anywhere that does the rectification first.

If this is what you do, what filter cut off and order (assuming you use a butter worth) do you use? Have you compared the output to performing the high pass first? If so, how do they compare?

Thank you

Stuart

whassani
07-31-2011, 12:11 PM
Hi Stuart,

I'm sorry, the high pass filter must be placed befor the full wave rectification filter. The cut-off frequency is about 30Hz.

What is the aim of your project?

You can contact me via "hassani.walid (at) gmail.com"

Regards,

Walid

hwambacq
08-01-2011, 02:55 AM
Hi,

Another important detail about the matlab command filtfilt is that the order you use for your filter coefficients (the A and B in the code above) doubles because of the recursive filter. You actually run the filter twice, once in forward direction, and a second time backwards. So in example given by Walid, the filter order is 8 and not 4 for as you might think from the code.

Regarding the processing itself, I almost every time use the following steps:
[RAW EMG (sEMG)] ->[bandpass filter, 20 - 500Hz] -> [rectify] -> [lowpass filter, averaging or RMS-calculation (no rectification needed in this case), depending on application]

In case of further questions, you can contact me by email as well (hans.wambacq<at>mech.kuleuven.be).

Best regards,

Hans

eolsen50
08-02-2011, 12:43 AM
Great post! There is also the free Matlab toolbox emglab; http://www.emglab.net/

/Emil

mcasteran77
08-02-2011, 02:59 AM
Hi Walid,

Good post on the MatLab filtering. The last part got me thinking. Do you high pass filter your data after the full wave rectification? I have always performed this before the rectification, and I haven't read anywhere that does the rectification first.

Stuart

Hi,

If you want, there are an Ebook "The ABC of EMG - A pratical introduction to kinesiological electromyography" by Peter Kornard 2005, it's very intersting !
http://www.demotu.org/aulas/controle/ABCofEMG.pdf

Have a good day

Matthieu

ecramp48
08-02-2011, 10:30 AM
Another couple of good books are Gait analysis : Theory and application by Rebecca L Craik and Carol A. Oatis ISBN 0-8-8016-6964-2 which has several excellent chapters on EMG, presented in a very readable and relatively easy to understand format.

For a thorough discussion of the mathematics of EMG signal processing you can read Signal Processing and Linear Systems for the Movement Sciences by David A. Winter and Aftab E. Patla ISBN 0-9699420-1-X.

drobbins99
08-04-2011, 03:55 AM
Hi,

I have been following this thread with interest as I am in the process of learning both Matlab and EMG filtering. As I have very limited knowledge of Matlab I am currently using a combination of Visual3D and Excel for filtering/analysis.

One thing I have noticed is there is somewhat of a lack of good text books on the area, I checked Google, Amazon and Alibris for the books recommended by Edmund Cramp, however as they are now out of print they are very hard to get hold of - and VERY expensive when they are (I saw copies at £130...).

Has anyone got recommendations for good text books in this area? Preferably text books with Q and A so I can work through them?

Thank you in advance for any help offered!

hwambacq
08-07-2011, 05:03 AM
As a start I would also recommend the ABC of EMG by Noraxon. This is a good start which covers almost every aspect, although in a quite general perspective. So if you want to get into details on certain aspects of EMG, there is more and better literature. In that case it might be useful to tell us a little about your plans. And also, if your budget is limited, think also about the cost of a – legal – Matlab license... this is also quite expensive.

Best regards,

Hans

drobbins99
08-09-2011, 04:10 AM
Hi Hans,

Thanks for replying. I have seen the ABC of EMG, it’s a nice book to get an idea of the basic process. What I would like to find is a more detailed text book covering advanced signal processing, particularly the different types of filters (Butterworth, chebyshev, critically damped, bessel, elliptical, FIR, IIR etc), the correct applications for each filter (e.g. removal of noise, data smoothing), the correct types of data each filter should be used for including advantages and disadvantages (e.g. ripple in pass or stop band, sharp or slow roll on/off) and techniques for establishing correct cut off frequency (e.g. Jackson Knee Method, Residual analysis, autocorrelation). My mathematical knowledge isn't great, so visual representations and detailed explanations would be ideal.

I am a full time student so I have managed to get the very nicely priced student edition of Matlab; I also have access to visual3D, though at this point I would prefer to learn Matlab as I get the impression being Matlab proficient will improve my employability after completing my studies.

Hopefully that should give you an idea of what I am looking for, if you (or anyone) know of any good textbooks/websites/learning resources I would really appreciate it if you could post the details.

Thanks
Dan

snauwelaerts21
08-09-2011, 04:18 AM
Hi,

I found "Electromyography for Experimentalists by Gans and Loeb" to be a very useful and practical guide. And it is affordable (\$45 on Amazon)!

Good luck,
Sandra

-----------------------------------------------------------------
Sandra Nauwelaerts, PhD
Research Associate

University of Antwerp
Department of Biology
http://webh01.ua.ac.be/funmorph/sandra

McPhail Performance Center
Michigan State University
http://cvm.msu.edu/dressage/
---------------------------------------------------------------------

ecramp48
08-09-2011, 12:46 PM
The Gans and Loeb book has been around for a long time (since 1986) but it contains an enormous amount of information that is relevant today. I'd second Sandra's recommendation - the book is one of my personal favorites and as a paperback at \$45, it's a bargain. Don't let the fact that a lot of the discussions are about animal EMG put you off this book, my copy is very dog-eared from years of use - it's a wonderfully practical book.

You may find that ELECTROMYOGRAPHY Physiology, Engineering and Noninvasive Applications, edited by Roberto Merletti and Philip Parker (John Wiley & Sons - ISBN-471-67580-6) provides a more thorough discussion of the methods in processing of EMG although this is a fairly dense book and unfortunately only available in hardback as far as I know. It's also available on Amazon but it's \$150.

A tutorial manual for our EMG Analysis and Graphing software is available on-line which contains an overview of the various processing methods - ftp://ftp.emgsrus.com/manuals/emgtutorial_ug.pdf - this covers a lot of the issues of EMG processing at a fairly basic level and might help you. In addition the EMG Analysis software (http://www.motion-labs.com/index_downloads.html) package can be downloaded and run in "demo" mode with the included C3D data files.

drobbins99
08-11-2011, 06:36 AM
Thanks for the replies, I have a had a look on Amazon and both these books luckily have a 'look inside' option, the Roberto Merletti and Philip Parker book looks like it could do the job, it’s a bit expensive at £90 but I might be able to get a loan through our library so I can judge before parting with money.

I have been speaking to the guys in our engineering department and the general feeling is that considering EMG is post processed we should not be using analogue filters at all and digital filter are definitely the way forward. Has anyone got any experience or thoughts on this point of view?

rmiller
08-16-2011, 10:57 AM
I will third the Gans & Loeb textbook recommendation, it's an excellent reference to have.

msalinas
08-18-2011, 03:42 PM
Hi-
I have read through the postings. I'm post-processing my EMG data. What I mean by that is that I'm not applying any filters real-time during the data collection.

My processing steps are:
1. De-mean the raw signal (subtract out the mean)
2. Apply a FIR Bandpass Filter (20-300 Hz)
3. Apply a Notch Filter at 60 Hz
4. Rectify (take absolute value)
5. Apply an FIR LowPass filter with cut-off freq = 10 Hz (To get Linear Envelope)

My questions:
Many of the postings suggest the MATLAB function 'butter' - IIR (recursive) filter. B/c you can do it real-time? Or is it b/c FIR filters takes too much computer time?

Does anyone apply the Notch Filter at 60 Hz? Any thoughts on this? I see a large spike at 60 Hz when I run an FFT on my signal. I think I'm picking up noise from the motorized treadmill.

Any thoughts on cutoff frequencies used to get the linear envelope? I used 10 Hz due to papers I've read. I'm curious what others are using. I'm collecting leg EMG & later I might collect arm EMG as well.

I would appreciate any comments. Thank you.

Mandy

msalinas
08-18-2011, 05:39 PM
Sorry - to be clear. I'm doing all the processing in MATLAB.

Mandy

Hi-
I have read through the postings. I'm post-processing my EMG data. What I mean by that is that I'm not applying any filters real-time during the data collection.

My processing steps are:
1. De-mean the raw signal (subtract out the mean)
2. Apply a FIR Bandpass Filter (20-300 Hz)
3. Apply a Notch Filter at 60 Hz
4. Rectify (take absolute value)
5. Apply an FIR LowPass filter with cut-off freq = 10 Hz (To get Linear Envelope)

My questions:
Many of the postings suggest the MATLAB function 'butter' - IIR (recursive) filter. B/c you can do it real-time? Or is it b/c FIR filters takes too much computer time?

Does anyone apply the Notch Filter at 60 Hz? Any thoughts on this? I see a large spike at 60 Hz when I run an FFT on my signal. I think I'm picking up noise from the motorized treadmill.

Any thoughts on cutoff frequencies used to get the linear envelope? I used 10 Hz due to papers I've read. I'm curious what others are using. I'm collecting leg EMG & later I might collect arm EMG as well.

I would appreciate any comments. Thank you.

Mandy

smiller45
08-24-2011, 01:38 PM
Hi Stuart,

I'm sorry, the high pass filter must be placed befor the full wave rectification filter. The cut-off frequency is about 30Hz.

What is the aim of your project?

You can contact me via "hassani.walid (at) gmail.com"

Regards,

Walid

Hi Walid,

Thank you for the information. I've been working with EMG on a number of projects and have always been questioning the processing methodology undertaken. As I'm sure you know, there is so much variability in how the processing is performed, with various reasons why. This is probably partly due to the natural variability of the signal, the differences in hardware, the differences in the validity of the data (referring to preparation etc), what you are using EMG for, amongst numerous other things. Even on this small listing there are a fair few different procedures suggested.

Stuart