I am trying to identify the start of a cycle which would be characterized by the maximum value. Although the data appears to be periodic, there is not a set number of points so I can't just break up the data into points of 50 and search for the max. However, I do know that the cycle cannot repeat before 20 pts (pt_limit) have elapsed which might be used a check. There is also not a trigger for the data due to the limitations of the DAQ hardware. I've included a few cycles below, but the actual data set will contain thousands of these quasi-periodic cycles.
Here is an example (sorry in advance for the longer data set):
data = [9147 9147 9513 9696 9696 9940 10093 10093 10246 10520 10520 10520 10795 10947 10947 11222 11772 11772 9452 4049 4049 4049 599 111 691 691 1515 2309 2309 2309 3072 3683 3683 4415 4995 4995 5453 5453 6063 6063 6643 7162 7162 7468 7742 7742 7742 8200 8536 8536 8841 9116 9116 9238 9543 9543 9543 9818 10001 10001 10246 10551 10551 10673 10673 10673 10917 10917 8749 4049 4049 1057 722 722 722 1210 2004 2004 2828 3683 3683 4293 4293 4751 4751 5270 5728 5728 6155 6643 6643 6643 7071 7437 7437 7712 8048 8048 8353 8353 8689 8689 9024 9269 9269 9513 9909 10215 10215 10215 10368 10673 10673 11008 11192 11192 11039 7864 7864 7864 2828 661 661 661 1332 1332 2309 2309 2950 2950 3683 4507 4507 5117 5667 5667 5667 6094 6521 6521 6949 7437 7437 7864 7864 8169 8169 8322 8689 9086 9086];
dt = [0 diff(data)];
t_thresh = -0.5; % threshold to identify changes (exclude noise)
ind = find(dt < t_thresh);
figure
set(gcf,'position',[50 50 (1080) (675)])
ax(1) = subplot(2,1,1);
plot(data, '.')
xlim([-5 155])
grid on
ax(2) = subplot(2,1,2)
plot(dt, '.')
grid on
hold on
plot(ind, dt(ind), 'ro')
xlim([-5 155])
linkaxes(ax,'x')
The data often contains repeat points which makes just looking for large changes in the derivative difficult.
The solution of this problem with the included data set would be:
cycle_ind = [18 68 116]
Thanks for the help
Any help would be greatly appreciated.
I would try filtering the data then looking for sign changes in the derivative, rather than thresholding it.
B = fir1(8,0.5);
newData = filtfilt(B,1,data);
dt = [0 sign(diff(newData))];
ddt = -[0 diff(dt)];
localMaxima = data(ddt>0);
idx = find(ddt>0);
plot(1:length(data),[data;newData;ddt*max(data)])