function burst_count = count_error_bursts(err_pos, max_burst_length) % err_pos: Vector of error positions % max_burst_length: Maximum length for which bursts are counted (e.g., 10) % Sort the error positions to ensure they're in increasing order err_pos = sort(err_pos(:).'); % Initialize burst_count array to hold the counts for each burst length burst_count = zeros(1, max_burst_length); if isempty(err_pos) return end % Find the differences between consecutive error positions diffs = diff(err_pos); % Find the start of the bursts (where the difference is greater than 1) burst_starts = [1, find(diffs > 1) + 1]; % Starts at index 1 and after gaps burst_ends = [find(diffs > 1), length(err_pos)]; % Ends where gaps are % Loop over the bursts for b = 1:length(burst_starts) burst_length = burst_ends(b) - burst_starts(b) + 1; % Check if the burst length exceeds any of the thresholds for i = 1:max_burst_length if burst_length == i burst_count(i) = burst_count(i) + 1; else end end end end