Create a logical array based on signal thresholds

16 vues (au cours des 30 derniers jours)
Cassandra Thompson
Cassandra Thompson le 19 Avr 2018
Commenté : Star Strider le 20 Avr 2018
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

Réponse acceptée

Star Strider
Star Strider le 19 Avr 2018

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 commentaires
Cassandra Thompson
Cassandra Thompson le 19 Avr 2018

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 le 20 Avr 2018
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by