Find starting point of a noisy array
3 views (last 30 days)
Show older comments
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 )
0 Comments
Accepted Answer
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
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"?
More Answers (1)
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
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?
See Also
Categories
Find more on Resizing and Reshaping Matrices 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!