fillgaps¶
Reconstruct missing events inside locally detected gaps.
Syntax¶
function [tn, dtn] = fillgaps(tk, varargin)
Description¶
TN = FILLGAPS(TK) reconstructs missing event timestamps in TK. TK must be a non-empty vector of finite event times in seconds, ordered strictly increasingly. FILLGAPS does not sort TK and does not remove false-positive detections; apply REMOVEFP explicitly first when that preprocessing is required. Every original timestamp is preserved exactly.
[TN, DTN] = FILLGAPS(TK) also returns the successive intervals of TN. An interval that spans a detected gap which cannot be reconstructed is represented by NaN in DTN. A gap remains unresolved when it exceeds the maximum duration or lacks two valid neighboring intervals on either side.
FILLGAPS(TK, DEBUG) enables interactive visual inspection when DEBUG is true. The upper plot shows the current interval series, detected gaps and detection threshold. For every reconstruction attempt, the lower plot shows the candidate intervals and the upper and lower validation limits; accepted candidates are green and rejected candidates are red. Execution pauses after each attempt until the user continues. If over-insertion is detected, the rejected attempt is shown first and the retained preceding attempt is then shown in green. The debug figure closes when processing finishes. DEBUG defaults to false and does not change numerical results.
FILLGAPS(TK, DEBUG, MAXGAPDURATION) attempts only detected gaps whose duration is at most MAXGAPDURATION seconds. Longer gaps remain in TN and are represented by NaN in DTN. The default is 10 seconds.
FILLGAPS(..., NAME, VALUE) accepts these parameters: - 'GapDetectionFactor' Detection factor, default 1.5. - 'CorrectionUpperFactor' Upper acceptance factor, default 1.15. - 'CorrectionLowerFactor' Over-insertion factor, default 0.75. - 'MinimumInterval' Absolute interval floor in seconds, default 0.5.
The factors must satisfy 0 < CorrectionLowerFactor < CorrectionUpperFactor <= GapDetectionFactor. Detected gaps are attempted segment-wide with one inserted event, then two, and so on. Interpolation uses PCHIP with the two nearest valid intervals on each side and preserves the exact duration between the original timestamps.
Source¶
Example¶
observed = [0 1 2 4 5 6];
cleaned = removefp(observed);
[tn, dtn] = fillgaps(cleaned, true);
See also¶
- REMOVEFP
- MEDFILTTHRESHOLD
- INTERP1