Author 
Message 
snovotill
Joined: Feb 8, 2013 Posts: 80

Posted: Feb 19, 2014 2:14 AM Post subject: Y_VectorToScalar  the new functions 

Hi Jarek, could you please add a short description to each of the following newish Y_VectorToScalar functions which are not yet in the manual? A couple seem obvious but best to confirm those too just to be sure.
MAGNITUDE AVERAGE_RS STREAM DOMINANT VALUE SELECTED_INDEX SELECTED_INDEX_SYNCH SUM OF SQUARES MIDDLE_POWER_VALUE MIDDLE_POWER_2_VALUE MIN_INDEX
Also with regard to above, I'm looking for \"MEAN_FREQUENCY\" which is universally used to measure muscle fatigue. If none of the above match, then would it be a strong candidate for addition? MNF definition: The frequency at which the average power within the epoch is reached. Where the product of the frequency value and the amplitude of the power spectrum is equal to the average of all such products throughout the complete spectrum. An average frequency which is calculated as the sum of product of the EMG power spectrum and the frequency divided by the total sum of the power spectrum. I have a more formal definition of this in PDF as well.
Note that BioEra already seems to support MIDDLE_POWER_2 which would be the Median Frequency aka MDF at which 50% of the total power within the epoch is reached.
Also wondering there a way to discover the vector length of a floaty pipe? PipeInfo doesn't seem to volunteer the value. This is actually accessible in some elements via PropertyGetter but if there's a more direct way that doesn't require triggering and is always up to date then I would use that.
Wow, that's a lot of words ;o) 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: Feb 19, 2014 2:41 PM Post subject: 

I updated manual:
http://www.bioera.net/manual.html#_Toc379808265
I don't understand the mean_frequency definition. And I am not sure it can be calculated here, since you mention EPOCH, which is a time period. Vector is usually used for an instant value (unless you construct it from a time period, e.g. STREAM_TO_VECTOR).
The vector size is not a pipe property, it is a signal property, so it should be read from the signal properties. There is a lot more other properties there than vector size, so I am not sure it makes sense to replicated them all into PipeInfo. The vector size doesn't change dynamically. It is defined at element reinit, like a signal rate and others. 


snovotill
Joined: Feb 8, 2013 Posts: 80

Posted: Feb 19, 2014 9:40 PM Post subject: 

Thanks for the manual update Jarek, that is very helpful =)
Regarding \"I am not sure it can be calculated here, since you mention EPOCH\". My bad: It's actually not that complicated. I should have said \"Vector\" in place of \"Epoch\". Epoch is just for noise removal by averaging after the calculation. The calculation is almost identical to \"MIDDLE_POWER_2_VALUE\" and so I've emailed you some PDF peerreviewed papers which explain it simply.
Regarding the Floatpipe vector length. I'd like to explain this a bit because people should be using it. Yes, I did get this succesfully from signal properties, and it is essential for calculating Spectral Density in uV/SqrtHz or Power Spectrum Density in nW/Hz, or frequency band ratios where the bandwidths are different for each region of interest. These are the defacto standard units for measurement of activity in noise spectra or any other randomlike spectra, and therefore it should be getting used often in EEG.
BioEra has the Y_VectorToScalar functions SUM and SUM_OF_SQUARES, which yield total (squrt)power in the vector, however that can't be used to compare vectors of unequal length, in which case one has to divide the total power by the vector length first, to yield spectral density as explained above. Then one can directly compare spectral ratios in different or even radically different bandwidths.
In this regard it would be a simple convenience to have a processing functions: SUM_SD=sum(Sn)/NumberOfBins SUM_OF_SQUARES=sum(Sn^2)/NumberOfBins which yield respectively spectral density and power spectrum density directly without need to extract vector size and then recalculate.
The current method of course, is to extract vector length via PropertyGetter and then use ExpressionEvaluator or CMixer to rescale per Hz. It seems to also be a good way to measure signal levels in a small bandwidth, above the noise floor in a larger bandwidth, as a ratio. 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: Feb 20, 2014 5:01 PM Post subject: 

I will add a new option in float (only) versions of VectorToScalar, which will do the mean frequency you described: WEIGHTED_VALUE
But I don't see a point to add new functions with \"/NumberOfBins\". That can be easily implemented with VectorExpressionEvaluator, with this expression: In1 / VectorSize for SUM, or In1 / (VectorSize^2) for SUM of squares. Added just before VectorToScalar.
That is also a recommendation to use more VectorExpressionEvaluator, which have a direct access to the vector size. And probably could be used to implement many functions, even the the above mean_frequency. It might not always be the most efficient way, but it is quite flexible. 


snovotill
Joined: Feb 8, 2013 Posts: 80

Posted: Feb 20, 2014 6:17 PM Post subject: 

So, I realized yesterday that \"Sum(Sn)/NumberOfBins\" is actually same as AVERAGE lol! But in the end it's the sum of squares version that I find much more useful, so all's good.
Speaking of the allpowerful VectorExpressionEvaluator, below are a few more examples for anyone who may be curious. I've tested all of these and they work as expected. Note the use of \"f\" on the constants to force \"float\" thereby preventing rounding errors:
Reverse the vector such that the elements come out in reversed order: (full credit to Jarek) InVector1[VectorSize  VectorIndex  1]
Apply an exponential gain curve along vector, for instance to balance a 1/f weighted vector. in this case a gain of 3 at far right and 1/3 at far left as per the \"3\" in the equation below: InVector1[VectorIndex]*Math.pow(3,2f*VectorIndex/VectorSize1f)
Apply a linear gain weighting curve along the vector, possibly to balance it for displaying. in this case a gain of 0.3(=10.7) at left and 1.7(=1+0.7) at far right: InVector1[VectorIndex]*((22*0.3)/VectorSize*VectorIndex+0.3)
P.S. while on the topic, is there a \"best way\" to embed a forloop into VectorExpressionEvaluator?
Thanks for the good discussion and the new MNF function. I'm going to try it next time I do chinups =) Always serious muscle fatigue! 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: Feb 20, 2014 6:29 PM Post subject: 

Yes, you can use loops in the advanced form of expression, for example:
Out1=In1 * Math.sqrt(2); for (float v : InVector1) { Out1 += v; }



angel61606
Joined: Jul 8, 2020 Posts: 55

Posted: May 31, 2021 5:54 AM Post subject: MDF and MNF 

Hi Jarek, I want to measure muscle fatigue, so I ended up here. I have multiple questions, first, to calculate MDF or median frequency, apparently I should use the product of MIDDLE_POWER_2 in my fft resolution, right? I thought that MIDDLE_POWER shows the index where the power (sum of squeres) above and below it is equal but it seems i was wrong and MIDDLE_POWER_2 is where the above and below power is equal.
second, to calculate the MNF, I read your explanation in manual about WEIGHTED_VALUE nand I am confused now. you said the input vector is the weight vector. By considering the fact that MNF is calculated as the sum of product of the EMG power spectrum and the frequency divided by the total sum of the power spectrum. this definition means that f or frequency is the weight vector so i should give f as input ? what is Vectormin or Vectormax ? 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: May 31, 2021 3:24 PM Post subject: 

Yes, MIDDLE_POWER_2 is sum of squares, and MIDDLE_POWER is just sum.
VectorMin and VectorMax are values defined in Signal Properties (visible in Advanced Properties). They are constant for each element set during intialization. For example SubVector element will set those to the range it created, and then they will propagate to all downstream elements. 


angel61606
Joined: Jul 8, 2020 Posts: 55

Posted: Jun 1, 2021 2:11 AM Post subject: 

oh I know MIDDLE_POWER is just sum, I meant when you use the term "Power" it means you calculated the squares. By the way I was wondering if by any chance you can send me the PDF file witch Snovotill was addressing to it in above discussion. he had sent it to you years ago .i know you probably do not have that file, but it was worth asking :) 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: Jun 1, 2021 9:47 AM Post subject: 

No sorry, I don't remember the file name. 


angel61606
Joined: Jul 8, 2020 Posts: 55

Posted: Jun 2, 2021 1:45 AM Post subject: 

Can I have Snovotil email address? I want to ask him some questions regarding the fatigue measurement. 


jarek
Joined: Oct 22, 2007 Posts: 892

Posted: Jun 8, 2021 4:10 PM Post subject: 

We don't share email addresses. Besides, this topic's notifications are sent to that email, so if he hasn't responded here then he probably doesn't use it any more. 
