0

I am calculating features from an EMG signal using MATLAB by segmenting the EMG signal into windows of 200 samples and then calculating the features of each window.

I need help trying to use a histogram feature please.

I can easily generate a vector of bins for one data window using the following code:

    binCount = 9;
    [histBins, ~] = histcounts(dataWindow, binCount);

However, the experiment I am following states the histogram is divided into 9 bins along a 3 standard deviation (sigma) threshold. I am confused as to how the threshold fits in with generating the histogram bins.

Is a 3 sigma threshold calculated for each data window and the data points falling within that threshold used to generate the histogram? Example pseudo code:

    for i = 1:numDataWindows
        dataWindow = windows(i);
        Calculate 3 standard deviations threshold using dataWindow
        Get data points from dataWindow that fall within threshold
        Generate histogram on data points within threshold
        ...
        Store histogram bins for later use
    end

Or is the 3 sigma threshold generated from the entire data signal, before windowing, so that the same threshold is then applied to each data window before generating each histogram?

humbleHacker
  • 437
  • 6
  • 17
  • Add a link to the experiment description? – Dan May 31 '16 at 21:17
  • Hey @Dan. Sorry for late response. After discussing this with my supervisor yesterday, we decided to go for with the first option. There's not much to the experiment description in the paper I'm looking at, but I've added an image to provide a visual explanation of what I mean: http://imgur.com/tphJrP9. I will take a data window and calculate a 3 sigma threshold for that window. Then I will take the signal that falls within that range (the topmost and bottommost dashed lines) and apply the histogram to that part of the signal. I will do this for every data window. – humbleHacker Jun 02 '16 at 12:54
  • So are you now able to answer the question or are you still stuck? – Dan Jun 02 '16 at 13:28
  • 1
    Sorry for late reply. It took a while to get a chance to write some MATLAB code to try it out. No, I'm not stuck any more. I will post the code I am using as an answer, so it's available for anyone else with a similar query or possible alternative to suggest – humbleHacker Jun 04 '16 at 11:56

1 Answers1

0

So, in response to my question, I went with the first option of taking a data window and calculating a 3 sigma threshold for that window. All data that falls within that threshold will then be used for the histogram feature. If anyone has an alternative viewpoint to this question, please feel free to comment or provide a solution of your own.

Here is the test MATLAB code I wrote for a single data window:

    % Get a single data window
    win = myChanWinData(1);

    % Find mean and standard deviation
    winMu = mean(win);
    winStd = std(win);

    % Get upper and lower boundaries of 3 sigma threshold
    k = 3;
    upper = winMu + winStd * k;
    lower = winMu - winStd * k;

    % Find indices where data falls within upper and lower boundaries
    threshStatus = not(abs(sign(sign(lower - win) + sign(upper - win))));
    myOnes = find(threshStatus == 1);

    % Extract the data values at the found positive indices
    newData = win(myOnes);

    % Generate histogram using data within our desired threshold
    numBins = 9;
    minV = min(newData);
    maxV = max(newData);
    [binCounts, ~] = histcounts(newData, numBins, 'BinLimits', [minV, maxV]);

Please note, the line where I find the indices (starting with "threshStatus =" ) was taken from the answer by @Angus to this question: http://uk.mathworks.com/matlabcentral/answers/8556-how-to-find-vector-elements-between-two-values-efficiently

humbleHacker
  • 437
  • 6
  • 17