LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Determining median power frequency of an EMG signal

Solved!
Go to solution

Here's one attempt.

0 Kudos
Message 11 of 15
(2,051 Views)

"He Who Lives by Express VIs, Dies by Express VIs".  I'm busy downloading the Biomedical Toolkit so I can test your code, should have something for you this evening, tomorrow morning at the latest (Famous Last Words) ...

 

Bob Schor

0 Kudos
Message 12 of 15
(2,033 Views)

So before I tried my hand at this, I (a) downloaded the Biomedical Toolkit so I could generate a simulated EMG, similar to what you did, and (b) looked up the definition of Median EMG Frequency (it is the Frequency that divides the Power Spectrum into regions of equal Power, or the Frequency where the integral = sum of the Power Spectrum reaches half the total sum).

 

So I simulated a single 10" EMG signal, using the default parameters of the Toolkit.  The Toolkit nicely provides an Ideal Spectrum for you --

Spectrum Preview.pngEMG Power Spectrum.png

As you can eyeball, it looks like a frequency around 150 Hz might divide the summed Power into roughly equal halves.  So how to code this?

 

The output of Simulate sEMG, like so many Express VIs, is carried in a Dynamic Wire, so getting rid of this is the first order of business.  Once we get a Waveform back, we can pass it through the Auto Power Spectrum and can plot the resulting Spectrum, as seen above.  It's noisy (it comes from a single 10-second simulation, so noise is expected, but the shape is similar to the Spectrum Preview).  Now it is only a question of summing the Power and dividing by two (to get Half Power) and doing "brute force integration", summing the spectrum one frequency at a time until the sum exceeds the Half Power.  Figure out what frequency this is, and you have your Median EMG Freq.  For the above example, the computed value was 177.2 Hz.

 

I've now told you how to do this.  I've got the VI that produced the above plot, and it is exactly as I described it in the previous paragraph.  In the hopes that you are sufficiently interested in both the Problem and in learning something about LabVIEW, I'm going to wait a day before posting it to give you a chance to "try this on your own" (it is a much better way to learn than to copy someone else's work).  Counting the Express VI, there are 12 functions and one Structure (a For loop, used for the Integral) in this code -- it is extremely straight-forward (and has no additional Express VIs).

 

Bob Schor

Message 13 of 15
(2,009 Views)

Another attempt but I was struggling to use the For loop you mentioned to get the median to work. Any comments on my mistakes?

0 Kudos
Message 14 of 15
(1,954 Views)
Solution
Accepted by BB24

Well, it's the Good News/Bad News Story.  As I posted previously, the Good News is that I solved your problem.  The Bad News is I didn't post the solution, hoping you would read what I wrote, follow my lead, and "do the right thing".  The further Bad News is that between then and now, the version I coded up got lost when I logged off my machine.

 

The Good News, however, is that I simply followed my previous post and recreated my earlier efforts.  Here it is:

BS-EMG.png

The only thing I kept from your code was the Express VI (though I wired two of its inputs, Block Size = 10 seconds and Sampling Rate = 1000 Hz).  This generates the signal whose (ideal) spectrum can be seen by looking "inside" the Express VI.

 

Dynamic Wires "get in the way" of understanding what you are doing, so I get rid of them.  Indeed, the Express VI returns an array of Waveforms, so I "Index Array" to get the Waveform.  I take the Auto Power Spectrum, plot it (and get a plot consistent with the ideal spectrum, and compute the Half-Power (by summing the Spectrum to get total power and dividing by 2).  Now all I have to do is start "integrating" (a fancy word for "adding") the Spectrum until I exceed this half-power -- the frequency that puts me "over the top" is, by definition, the Median Power Frequency (OK, you can argue that it might be one frequency too big ...).

 

Notice the total absence of Express VIs and Dynamic Wires.  They are absolutely not needed, and (I would argue) "get in the way" of understanding the deeper meaning of the problem and its solution.

 

Bob Schor

Message 15 of 15
(1,927 Views)