How to find peaks in timeseries data?

6 次查看(过去 30 天)
I am using following matlab lines to find number of peaks in NDVI time series. However, it is not giving any peak value in timeseries data.
for i = 1:size(ndvi_data, 1)
location_data = ndvi_data(i, :);
pks, locs, ~, prominences] = findpeaks(location_data, 'MinPeakProminence', 0.1, 'MinPeakHeight',0.35, 'MinPeakDistance', 5);
num_peaks = numel(pks);
disp(num_peaks);
I am attaching input data file and request you to please suggest me how to find the peaks in ndvi time series data.

回答(1 个)

Star Strider
Star Strider 2024-6-21
Your code works when I run it, alhough not all ‘location_data’ vectors have identifiable peaks (all below the 'MinPeakHeight' value). .
I added a waterfall plot to demonstrate the peaks and locations.
Try this —
ndvi_data = readmatrix('ndvi.csv')
ndvi_data = 203x24
0.2130 0.2210 0.2287 0.2359 0.2426 0.2484 0.2537 0.2582 0.2577 0.2413 0.2547 0.3545 0.2787 0.3377 0.2979 0.3086 0.2883 0.2817 0.2711 0.2601 0.2573 0.2549 0.2574 0.2555 0.2173 0.2251 0.2325 0.2397 0.2463 0.2521 0.2573 0.2640 0.2717 0.2827 0.3194 0.3385 0.2529 0.3293 0.2736 0.3027 0.2815 0.2691 0.2634 0.2564 0.2543 0.2545 0.2555 0.2540 0.2206 0.2279 0.2349 0.2414 0.2474 0.2523 0.2554 0.2624 0.2807 0.3167 0.3630 0.3648 0.2871 0.3342 0.2682 0.3021 0.2804 0.2647 0.2590 0.2566 0.2531 0.2522 0.2548 0.2524 0.2230 0.2296 0.2359 0.2417 0.2463 0.2490 0.2496 0.2531 0.2719 0.3170 0.3616 0.3390 0.2530 0.3280 0.2754 0.3039 0.2816 0.2672 0.2618 0.2566 0.2544 0.2516 0.2553 0.2543 0.2246 0.2306 0.2363 0.2415 0.2456 0.2477 0.2470 0.2456 0.2527 0.2957 0.3440 0.3375 0.2708 0.3327 0.2693 0.2970 0.2765 0.2639 0.2591 0.2562 0.2535 0.2564 0.2562 0.2575 0.2259 0.2313 0.2365 0.2418 0.2468 0.2510 0.2528 0.2522 0.2544 0.2650 0.3119 0.3447 0.2625 0.3341 0.2731 0.3007 0.2819 0.2668 0.2604 0.2563 0.2538 0.2562 0.2559 0.2568 0.2270 0.2317 0.2366 0.2421 0.2489 0.2572 0.2646 0.2657 0.2520 0.2302 0.2548 0.3610 0.2767 0.3359 0.2935 0.3039 0.2837 0.2729 0.2638 0.2570 0.2554 0.2553 0.2581 0.2559 0.2283 0.2323 0.2364 0.2415 0.2494 0.2618 0.2772 0.2868 0.2707 0.2287 0.2511 0.3380 0.2777 0.3423 0.3053 0.3174 0.2949 0.2957 0.2883 0.2744 0.2589 0.2552 0.2561 0.2524 0.2299 0.2333 0.2364 0.2402 0.2466 0.2599 0.2814 0.3017 0.2998 0.2434 0.2576 0.3907 0.2701 0.3313 0.2887 0.3082 0.2861 0.2692 0.2557 0.2515 0.2529 0.2530 0.2538 0.2512 0.2323 0.2354 0.2378 0.2401 0.2435 0.2522 0.2744 0.2891 0.2763 0.2457 0.2864 0.3682 0.2913 0.3351 0.2690 0.3038 0.2827 0.2665 0.2595 0.2568 0.2530 0.2524 0.2552 0.2522
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
for i = 1:size(ndvi_data, 1)
location_data = ndvi_data(i, :);
[pks{i}, locs{i}, ~, prominences{i}] = findpeaks(location_data, 'MinPeakProminence', 0.1, 'MinPeakHeight',0.35, 'MinPeakDistance', 5);
num_peaks = numel(pks{i});
disp("Row "+i+" Nr Peaks = "+num_peaks);
end
Row 1 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 2 Nr Peaks = 0 Row 3 Nr Peaks = 1 Row 4 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 5 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 6 Nr Peaks = 0 Row 7 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 8 Nr Peaks = 0 Row 9 Nr Peaks = 1 Row 10 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 11 Nr Peaks = 0 Row 12 Nr Peaks = 1 Row 13 Nr Peaks = 0 Row 14 Nr Peaks = 1 Row 15 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 16 Nr Peaks = 0 Row 17 Nr Peaks = 1 Row 18 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 19 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 20 Nr Peaks = 0 Row 21 Nr Peaks = 1 Row 22 Nr Peaks = 1 Row 23 Nr Peaks = 1 Row 24 Nr Peaks = 1 Row 25 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 26 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 27 Nr Peaks = 0 Row 28 Nr Peaks = 1 Row 29 Nr Peaks = 1 Row 30 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 31 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 32 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 33 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 34 Nr Peaks = 0 Row 35 Nr Peaks = 2 Row 36 Nr Peaks = 2 Row 37 Nr Peaks = 2 Row 38 Nr Peaks = 2 Row 39 Nr Peaks = 2 Row 40 Nr Peaks = 2 Row 41 Nr Peaks = 2 Row 42 Nr Peaks = 2 Row 43 Nr Peaks = 2 Row 44 Nr Peaks = 2 Row 45 Nr Peaks = 2 Row 46 Nr Peaks = 2 Row 47 Nr Peaks = 2 Row 48 Nr Peaks = 2 Row 49 Nr Peaks = 2 Row 50 Nr Peaks = 2 Row 51 Nr Peaks = 2 Row 52 Nr Peaks = 2 Row 53 Nr Peaks = 2 Row 54 Nr Peaks = 2 Row 55 Nr Peaks = 2 Row 56 Nr Peaks = 2 Row 57 Nr Peaks = 2 Row 58 Nr Peaks = 2 Row 59 Nr Peaks = 2 Row 60 Nr Peaks = 2 Row 61 Nr Peaks = 2 Row 62 Nr Peaks = 2 Row 63 Nr Peaks = 2 Row 64 Nr Peaks = 2 Row 65 Nr Peaks = 2 Row 66 Nr Peaks = 2 Row 67 Nr Peaks = 2 Row 68 Nr Peaks = 2 Row 69 Nr Peaks = 2 Row 70 Nr Peaks = 2 Row 71 Nr Peaks = 2 Row 72 Nr Peaks = 2 Row 73 Nr Peaks = 2 Row 74 Nr Peaks = 2 Row 75 Nr Peaks = 2 Row 76 Nr Peaks = 2 Row 77 Nr Peaks = 2 Row 78 Nr Peaks = 2 Row 79 Nr Peaks = 2 Row 80 Nr Peaks = 2 Row 81 Nr Peaks = 2 Row 82 Nr Peaks = 2 Row 83 Nr Peaks = 2 Row 84 Nr Peaks = 2 Row 85 Nr Peaks = 2 Row 86 Nr Peaks = 2 Row 87 Nr Peaks = 2 Row 88 Nr Peaks = 2 Row 89 Nr Peaks = 2 Row 90 Nr Peaks = 2 Row 91 Nr Peaks = 2 Row 92 Nr Peaks = 2 Row 93 Nr Peaks = 2 Row 94 Nr Peaks = 2 Row 95 Nr Peaks = 2 Row 96 Nr Peaks = 2 Row 97 Nr Peaks = 2 Row 98 Nr Peaks = 2 Row 99 Nr Peaks = 2 Row 100 Nr Peaks = 2 Row 101 Nr Peaks = 2 Row 102 Nr Peaks = 2 Row 103 Nr Peaks = 2 Row 104 Nr Peaks = 2 Row 105 Nr Peaks = 2 Row 106 Nr Peaks = 2 Row 107 Nr Peaks = 2 Row 108 Nr Peaks = 2 Row 109 Nr Peaks = 2 Row 110 Nr Peaks = 1 Row 111 Nr Peaks = 2 Row 112 Nr Peaks = 2 Row 113 Nr Peaks = 2 Row 114 Nr Peaks = 2 Row 115 Nr Peaks = 2 Row 116 Nr Peaks = 2 Row 117 Nr Peaks = 2 Row 118 Nr Peaks = 2 Row 119 Nr Peaks = 2 Row 120 Nr Peaks = 2 Row 121 Nr Peaks = 2 Row 122 Nr Peaks = 2 Row 123 Nr Peaks = 2 Row 124 Nr Peaks = 2 Row 125 Nr Peaks = 2 Row 126 Nr Peaks = 2 Row 127 Nr Peaks = 2 Row 128 Nr Peaks = 2 Row 129 Nr Peaks = 2 Row 130 Nr Peaks = 2 Row 131 Nr Peaks = 2 Row 132 Nr Peaks = 2 Row 133 Nr Peaks = 2 Row 134 Nr Peaks = 2 Row 135 Nr Peaks = 2 Row 136 Nr Peaks = 2 Row 137 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 138 Nr Peaks = 0 Row 139 Nr Peaks = 1 Row 140 Nr Peaks = 1 Row 141 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 142 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 143 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 144 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 145 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 146 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 147 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 148 Nr Peaks = 0 Row 149 Nr Peaks = 1 Row 150 Nr Peaks = 1 Row 151 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 152 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 153 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 154 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 155 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 156 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 157 Nr Peaks = 0 Row 158 Nr Peaks = 1 Row 159 Nr Peaks = 1 Row 160 Nr Peaks = 1 Row 161 Nr Peaks = 1 Row 162 Nr Peaks = 1 Row 163 Nr Peaks = 1 Row 164 Nr Peaks = 1 Row 165 Nr Peaks = 1 Row 166 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 167 Nr Peaks = 0 Row 168 Nr Peaks = 1 Row 169 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 170 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 171 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 172 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 173 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 174 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 175 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 176 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 177 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 178 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 179 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 180 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 181 Nr Peaks = 0 Row 182 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 183 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 184 Nr Peaks = 0 Row 185 Nr Peaks = 1 Row 186 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 187 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 188 Nr Peaks = 0 Row 189 Nr Peaks = 1 Row 190 Nr Peaks = 1 Row 191 Nr Peaks = 1 Row 192 Nr Peaks = 1 Row 193 Nr Peaks = 1 Row 194 Nr Peaks = 1 Row 195 Nr Peaks = 0 Row 196 Nr Peaks = 1 Row 197 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 198 Nr Peaks = 0 Row 199 Nr Peaks = 1 Row 200 Nr Peaks = 1
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 201 Nr Peaks = 0
Warning: Invalid MinPeakHeight. There are no data points greater than MinPeakHeight.
Row 202 Nr Peaks = 0 Row 203 Nr Peaks = 1
figure
waterfall(ndvi_data)
hold on
for k = 1:size(ndvi_data, 1)
scatter3(locs{k}, k, pks{k}, 'r^', 'filled')
end
hold off
xlabel('Columns')
ylabel('Rows')
title('‘waterfall’ Plot Showing Identified Peaks')
Make appropriate changes to get the result you want.
.

类别

Help CenterFile Exchange 中查找有关 Time Series Events 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by