MATLAB: Find starting point of a noisy array

averagenoisy signal

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 )

Best Answer

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);