Find starting point of a noisy array

4 views (last 30 days)
How can I find the the starting point of A array and calculate average starting from starting points to 2 seconds
A=[0 0 0 0 0 -0.01 -0.2 0.3 0.4 0.5 0 0 0 0 0 0 0.01 0.02 0.03 0.04 0.1 0.2 0.3 0.4 0.7 0.8 1 1.2 1.3 1.4 1.5]
Time=[0 0.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8 3 3.1]
By removing the noise the starting point should be A(17) which is equal to 0.01
Then calculate average of A(from 0.01 to 1.2 )

Accepted Answer

Image Analyst
Image Analyst on 21 Jul 2018
Below is a solution. By the way, you still have not explained what "B" is when you said "How can I find the the starting point of B array". So, what is B???
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
A=[0 0 0 0 0 -0.01 -0.2 0.3 0.4 0.5 0 0 0 0 0 0 0.01 0.02 0.03 0.04 0.1 0.2 0.3 0.4 0.7 0.8 1 1.2 1.3 1.4 1.5];
Time=[0 0.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8 3 3.1];
% Find positive values of A.
validIndexes = A > 0
% Find last zero.
lastZeroIndex = find(A <= 0, 1, 'last')
validIndexes(1:lastZeroIndex) = false;
% Find index where A first exceeds 1.2
lastIndex = find(A > 1.2, 1, 'first')
% Get A that meet the criteria of both positive and past the last zero.
validIndexes(lastIndex : end) = false;
meanValue = mean(A(validIndexes))
plot(Time, A, 'bs-');
% Draw lines over the region.
line([Time(17), Time(17)], ylim, 'Color', 'r', 'LineWidth', 2);
line([Time(lastIndex), Time(lastIndex)], ylim, 'Color', 'r', 'LineWidth', 2);
grid on;
caption = sprintf('A vs. Time, mean in region = %.3f', meanValue);
title(caption, 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('A', 'FontSize', fontSize);
% Plot valid indexes:
hold on;
plot(Time(validIndexes), A(validIndexes), 'ro', 'MarkerSize', 15);
  2 Comments
joms
joms on 21 Jul 2018
Edited: Image Analyst on 21 Jul 2018
This is perfect answer. I was referring to A Array, not B, I corrected my question above. Thank you very much.
Image Analyst
Image Analyst on 21 Jul 2018
OK, I was wondering if B was A(lastZeroIndex : lastIndex).
Anyway, are we done enough for you to click "Accept this answer"?

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 21 Jul 2018
I don't see anything special about 17
so how about this:
clc; % Clear the command window.
clearvars;
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
A=[0 0 0 0 0 -0.01 -0.2 0.3 0.4 0.5 0 0 0 0 0 0 0.01 0.02 0.03 0.04 0.1 0.2 0.3 0.4 0.7 0.8 1 1.2 1.3 1.4 1.5];
Time=[0 0.1 .2 .3 .4 .5 .6 .7 .8 .9 1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.8 3 3.1];
B = A(17:end); % Not really sure how you define "B" so I'm guessing.
% Find index where A first exceeds 1.2
lastIndex = find(A > 1.2, 1, 'first')
meanValue = mean(A(17:lastIndex))
plot(Time, A, 'bs-');
% Draw lines over the region.
line([Time(17), Time(17)], ylim, 'Color', 'r', 'LineWidth', 2);
line([Time(lastIndex), Time(lastIndex)], ylim, 'Color', 'r', 'LineWidth', 2);
grid on;
caption = sprintf('A vs. Time, mean in region = %.2f', meanValue);
title(caption, 'FontSize', fontSize);
xlabel('Time', 'FontSize', fontSize);
ylabel('A', 'FontSize', fontSize);
  3 Comments
Image Analyst
Image Analyst on 21 Jul 2018
And how are we supposed to know that the first peak is a noise peak while the second peak is not? Do you have some rule for that?
joms
joms on 21 Jul 2018
a valid data are the non zero and constant positive during the rest of the data. Thanks

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!