Create a logical array based on signal thresholds

조회 수: 9 (최근 30일)
Cassandra Thompson
Cassandra Thompson 2018년 4월 19일
댓글: Star Strider 2018년 4월 20일
How can i create a logical array of zeros and ones based on a threshold (mean +- 3SD) of my signal? I would like to assign a 0 whenever the signal (FxRMS) is above the UpperFxThreshold and below the LowerFxThreshold. When the signal is between these two threshold levels, then i would like to assign a 1. I have plotted the logical array (code below) against my data however, it is incorrect, and i am unsure of how to correct it. I have attached a copy of the script that i have written and example data.
i
%Create a logical array of force data, where: force above and or below threshold limit = 0,
%and force between threshold limits = 1
FxLogic = zeros(size(FxRMS));
for iiFx = 500:numel(FxRMS)
if FxRMS(iiFx)>UpperFxThresh
FxLogic(iiFx) = 0;
elseif FxRMS(iiFx)<LowerFxThresh
FxLogic(iiFx) = 0;
else LowerFxThresh<FxRMS(iiFx)<UpperFxThresh
FxLogic(iiFx) = 1;
end
end

채택된 답변

Star Strider
Star Strider 2018년 4월 19일

If I understand correctly what you are doing, and if ‘FxRMS’ is a vector, you can completely eliminate the loop and do your test in one line:

FxLogic = (FxRMS > LowerFxThresh) & (FxRMS < UpperFxThresh);

This sets ‘FxLogic’ to logical 1 or true for ‘FxRMS’ within the limits, and 0 elsewhere. Logical arrays become numeric arrays by doing any operation on them, for example putting a ‘+’ in front of it:

FxLogic = +((FxRMS > LowerFxThresh) & (FxRMS < UpperFxThresh));

producing a double vector.

This should work.

  댓글 수: 4
Cassandra Thompson
Cassandra Thompson 2018년 4월 19일

FxRMS is medio-lateral ground reaction force (sampled @1000Hz, for 20seconds) during a jump-landing task.

I wanted to ignore any samples prior to ground contact and chose the 500th sample arbitrarily, based on observations of the approximate timing of ground contact between trials, but it's not accurate.

I have created a separate variable to identify the time of ground contact called 'tGND' - and you have just given me the idea to start indexing at the time of ground contact instead.

iiFx = tGND(FxRMS):numel(FxRMS)

So thank you again!

Star Strider
Star Strider 2018년 4월 20일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by