Data: https://drive.google.com/file/d/0B7G3oUuZG1TwYWhMVUhSQzNwTEk/view?usp=sharing
Here I have 20 datasets collected from custom built EMG sensors monitoring a users face. I am particularly just interested in the 3rd and 6th rows of the data ( These are the sensors monitoring for Blinks ). I am interested in automating the process of detecting where the blink features occur, clipping the data in a window around the blink, and storing that for analysis.
Here is the full data set:
ListLinePlot[blinkData, PlotRange -> Full]
blinkData =
Flatten[Part[Import["FilePath"], {3,6}]];
Manipulate[
blinkSmoothDistribution1D =
SmoothKernelDistribution[blinkData[[n ;; m]]];
blinkEntropy =
NIntegrate[
With[{f = PDF[blinkSmoothDistribution1D, x]},
If[f > 0, f Log[f], 0]], {x, -\[Infinity], \[Infinity]},
MaxRecursion -> 20, WorkingPrecision -> 12];
ListLinePlot[blinkData[[n ;; m]], PlotRange -> Full,
PlotLegends -> {"Entropy: " <> ToString[blinkEntropy]}]
, {n, 1, m - 1, 1}, {m, 100, Length[blinkData], 1}]
Here I have manually found the window that the feature exists in and calculated the differential entropy for that window, as this is the feature of the data I am most interested in. I am interested to know if there is a way to write a function to find this window where the differential entropy is actually the lowest - that corresponds to when the user was blinking.
Mvariance[x_, p_] := (
Maouty = {};
Stopv = Length[x] - p + 1;
If[p > Length[x],
Print["moving window size must NOT be greater than ", Length[x]],
Print["mvariance is "]];
Do[AppendTo[Maouty, Variance[x[[i ;; i + p - 1]]]], {i, Stopv}];
Return[Maouty] )
variance = Mvariance[blinkData, 1000]
Per Bill's suggestion I have calculated the moving variance of a the data with a window size of 1000 and I can clearly see where the blink emerges. Now how do I extract the range of this spike and correspondingly clip the other data set appropriately?
Module[{var, first, last}, var = MovingMap[Variance, Differences@#, 1000]; first = First@FirstPosition[var, x_ /; x > 0.000025, Length@# + 1]; last = first - 1 + First@FirstPosition[var[[first ;;]], x_ /; x <= 0.000025, Length@var - first + 1]; ListLinePlot[#[[first + 250 ;; last + 750]], PlotRange -> All]] &@ Import["Blink-3 #20.csv"][[3]]
$\endgroup$ – kirma Feb 29 '16 at 19:39FindPeaks
function. $\endgroup$ – kirma Feb 29 '16 at 19:52