Oct 21, 2011 4:01 PM
EMG Signal Linear Regression implementation

Like (0)
Hello,
i'm trying to implement a linear regression of emg signal....
i'm reading a file that has the emg signal, and I need to implement linear regression on RMS and FFT signal.
I've read some posts, and was suggested to use the Curve Fitting VI....
I'm using lv2010.
As in the literature, by the slope of linear regression could detect fatigue of muscle.....
Could someone help me to get it works?!
Attached the VI and the signal.
Hi Ramon,
I didn't see you VI, but I guess you need to do linear fitting for each muscle contraction instead of fitting for the whole signal which may includes several contractions.
Thanks!
ZJ Gu
Hey,
I think this is linear fitting for MPF not for EMG itsself. The time axis is duration for contraction?
Thanks!
ZJ Gu
Yeah, ZJ Gu!!
X axis is duration for contraction.... and Y axis is the frequencies values of the contraction....
like in some articles, could Y be mean frequency (MPF), median frequency (MDF), RMS values (in time domain)...
but until now i don't have success....
When I read the EMG file (signal.lvm), how to separate Y and X values?
Should read the whole file, or by small samples?
Thanks!
Hi,
Usually, you calculate the MDF or MPF by using small moving windows of your signal (like 250 msec) with or without interleave. So with a 30 seconds signal and taking 250 msec windows of it without interleaving you would get 120 values (30000 msec / 250 msec) of MDF or MPF that you could plot on a graph.
HTH,
Michel
Hi Exovede,
check if I'm right:
I'm using a sampling rate of 2000 Hz. As whole signal has 30 s of duration, there will be 60.000 points .
So, to apply a window of 0,5 s, can I simply configure the Read Meas File to read 1000 points in a while loop until EOF?
That is what i'm already doing....
Hi Ramon,
Yes, you could do it that way. For each 1000 points, pass a Hanning window on this 1000points signal then compute the MDF (and/or MPF) then you would have 60 values to plot vs time (each value would correspond to a 0,5 second increment).
Salutations,
Michel
Hi Exovede,
I will try to make yours suggestion....
Thanks for the tip.
have you take a look in my VI ?
it's missing only the hanning window?
should i use the "curve fitting VI" to generate the "best fit" or use the "linear fitting vi" ?
See ya!
Hi Ramon,
No, I haven't look your VI...we're still at LV2009.
The fitting for the MDF/MPF vs Time is, usually, a linear fitting and the result is a slope in Hertz/second unit.
Salutations,
Michel
Hello again Exovede,
i try to do what you've suggested.... but no sucess archived.....
I save the vi to lv9.
There are 2 tries i shoot. (regression and regression02)....
If you could take a look at them, please.
Use the signal example that is already posted (signal01.lvm).
Thanks a lot!
Hi Ramon,
I can't open the vi's you sent...they seem to still be in LV2010 version.
However, before doing the spectral computing (MDF and/or MPF), I guess you removed the baseline (removing the mean of the 1000points signal) because if you don't and you have an offset in your signal, the values of MDF/MPF won't be the "real" ones.
Salutations,
Michel
Hi again Ramon,
I've taken a look at your signal. There seems to be multiple "bursts" but when you check for fatigue, the level of force ask should be the same then you see a small decline in the amplitude of the raw emg over time and if fatigue happens a decline in the MDF/MPF also in time (shifting toward lower frequencies).
Salutations,
Michel
Hi Michel,
I did what you suggested, to read 1000 point, filter with hanning windows, then applying FFT transform, and after that, the mean calculation. There are 60 values.
I don't realize how to implement linear fitting now. Should I save the mean values in another file before apply linear fitting? Or how to get those values into a array? In linear fitting, Y and X should have same size... now I have 60 values (for Y) , and 60000 values on time axis.... i'm still confusing....
I attached the VI that implements until the power spectrum transform, for lv 8.5.
Thanks!
Hi Ramon,
I've taken a look at your vi. You need to get the correct algorithms for computing the median and/or the mean frequencies. You can't just do the mean of your power spectrum like that and get something "interesting".
For the median frequency:
1.Add all the values of your power spectrum (PSUM)
2.Now, do a cumulative sum of your spectrum until the sum reaches half of (PSUM)...the index, multiplied by your frequency step, will be the median frequency.
For the mean frequency:
1. Take your power spectrum and multiply it by a vector representing the frequencies associated with each value of the power
2. Add all the values of the preceding step (PFSUM)
3. Divide PFSUM by PSUM to get the mean frequency.
Here are the steps:
[Loop]
1. Read a 1000 points (corresponding to 0,5 second)
2. Remove the mean of this 1000points signal
3. Pass it through a Hanning window
4.Do your spectral analysis (medium or mean frequency) > you'll get one point representing the desired frequency.
5. Loop for all the 1000points blocks
[End of loop]
Now, you have 60 "frequency" points. Those will be on the Y axis
The X axis will be the time...each of your "frequency" points is on a 0,5 second increment.
So, you'll have a vector of 60 points for your Y axis (frequencies) and a vector of 60 points [0.5,1.0,1.5,2.0,...,30.0] representing your time in seconds (you need to build that one). Just feed those two vectors in the linear fitting vi and you'll get the best "curve" and the slope.
Salutations,
Michel