필터 지우기
필터 지우기

Find starting point of a noisy array

조회 수: 2 (최근 30일)
joms
joms 2018년 7월 21일
댓글: Image Analyst 2018년 7월 21일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by