Finding series/pattern in an array

2 views (last 30 days)
Niravkumar Ambaliya
Niravkumar Ambaliya on 13 Nov 2019
I have a large vector, for example, A = [0 0 0 1 3 6 9 10 10 10 10 10 0 0 0 0 2 4 6 9 10 10 10 10 0 ....... ]
I want to find out signal rise time for each rise, for example in this case signal going from 0 to 10. Also after signal has reached 10, how long does it stays at 10.
This sequence of rise and steady-state can be multiple time in an array.
Note: Each sample(datapoint) is 10 msec apart
Rise_Time.PNG
.

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 13 Nov 2019
I have answered this question with help of @Jan Answer's here
A =[0 0 0 1 3 6 9 10 10 10 10 10 0 0];
d=[true,diff(A)~=0,true];
n=diff(find(d)) % Thes Gives the Time sequence
t=10:10:length(A)*10;
plot(t,A); % Get Hints
ylim([-5 12]); % Lim on y axes
From the n value, which gives the repeatation of A, you can multiply by 10 and plot are per your requirements.
245.png
  1 Comment
Niravkumar Ambaliya
Niravkumar Ambaliya on 13 Nov 2019
Thanks for the answer. But I don't want to plot the signal. I want to know how many cycles (Rise-Steady State-Fall) are there in an array. Additionally, for each cycle what is the rise time (time taken from 0 to 10. And once signal reached 10, for how long does it stay there.
A = [0 0 0 1 3 6 9 10 10 10 10 10 0 0 0 0 2 3 4 6 7 9 10 10 10 10 0];
Output expected:
Number of cycles: 2
1st cycle rise time = 5 samples*10 = 50 msec;
1st cycle steady time = 4 samples*10 = 40 msec;
2nd cycle rise time = 7 samples*10 = 70 msec;
3rd cycle steady time = 3 samples*10 = 30 msec;

Sign in to comment.


Daniel M
Daniel M on 13 Nov 2019
Edited: Daniel M on 13 Nov 2019
If you have the signal processing toolbox you can do this pretty easily using the functions risetime and pulsewidth. You just have to play with the settings. Typically rise time is characterized by the time between the bottom 10% and upper 90% of your signal, and this is the default of risetime, but here I show you how you can obtain it for the very bottom and very top.
A = [0 0 0 1 3 6 9 10 10 10 10 10 0 0 0 0 2 4 6 9 10 10 10 10 0];
% get the rise time
% can't use [0 100] because it requires a tolerance level
% but since your signal is bounded by 0 and 10 with no noise, a very low tolerance works
% But we will have to round the output up.
risetime(A,1,'PercentReferenceLevels',[0.1 99.9],'Tolerance',0.01)
% ans =
% 4.8802 4.9102
And wrap that function call in ceil() will return 5 and 5. See the attached figure.
For the pulsewidth, use
pulsewidth(A,1,'MidPercentReferenceLevel',99.98,'Tolerance',0.01)
% ans =
% 4.0572 3.0572
In this case, use floor() to round the answer down to 4 and 3.
  1 Comment
Niravkumar Ambaliya
Niravkumar Ambaliya on 13 Nov 2019
Unfortunately I do not have signal processing toolbox. Is there a way without signal processing toolbox?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!