Finding series/pattern in an array
2 次查看(过去 30 天)
显示 更早的评论
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
.
0 个评论
回答(2 个)
KALYAN ACHARJYA
2019-11-13
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.
Daniel M
2019-11-13
编辑:Daniel M
2019-11-13
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!