How do I collect all data strings of an array that meet 2 criteria
Show older comments
I am trying to collect data from an array that meet two criteria. More specifically, I want to start collecting the values of an array that cross a threshold and continue to collect the values in the array until they fall below another threshold. I can do the first part, but I can't figure out how to continue to collect the values until they fall below the second threshold (ThresholdOFF in the below attempt). Can you help me collect continuous values of the array (x) that cross above Threshold and continue to collect until the next value that falls below ThresholdOFF? Then I want the indices of the values that meet these criteria. Here is what I have so far:
Fs = 8000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
Fc = 60; % hertz
x = cos(2*pi*Fc*t);
% Plot the signal versus time:
figure;
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;
StDevPower=std(x);
MeanPower=mean(x);
Threshold=((StDevPower*1)+MeanPower);
ThresholdOFF=((StDevPower*0.5)+MeanPower);
AboveSD=[];
for j=1:length(x)
if x(j)>Threshold
AboveSD=[AboveSD; x(j)];
end
end
figure, plot(AboveSD)
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!