Find starting point of a noisy array

3 次查看(过去 30 天)
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 )

采纳的回答

Image Analyst
Image Analyst 2018-7-21
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 个评论
joms
joms 2018-7-21
编辑:Image Analyst 2018-7-21
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 2018-7-21
OK, I was wondering if B was A(lastZeroIndex : lastIndex).
Anyway, are we done enough for you to click "Accept this answer"?

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2018-7-21
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 个评论
Image Analyst
Image Analyst 2018-7-21
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 2018-7-21
a valid data are the non zero and constant positive during the rest of the data. Thanks

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by