nanfilter¶
Implements filter function with support for NaN values.
Syntax¶
function y = nanfilter(b, a, x, maxgap)
Description¶
Y = NANFILTER(B, A, X) filters the data in vector, matrix, or N-D array, X, with the filter described by vectors A and B to create the filtered data Y with NaN values preserved.
Y = NANFILTER(B, A, X, MAXGAP) allows specifying a maximum gap size MAXGAP.
Algorithm: 1. For each column, classify NaN sequences as boundary gaps, internal short gaps (<= MAXGAP), or preserved internal long gaps (> MAXGAP). 2. Preserve boundary and long internal gaps as NaN and use them to split the signal into candidate finite segments. 3. Interpolate short internal gaps within each candidate segment. 4. Process filterable segments independently using filter. 5. Leave segments shorter than max(length(B), length(A)) as NaN.
Source Code¶
Examples¶
% Filter a noisy signal with NaN gaps
fs = 1000;
t = 0:1/fs:1;
signal = sin(2*pi*50*t)' + 0.1*randn(length(t),1);
signal(100:150) = NaN; % Add NaN gap
% Design and apply filter
[b, a] = butter(4, 0.1);
filtered = nanfilter(b, a, signal, 10);
See Also¶
- FILTER
- NANFILTFILT
-
INTERPGAP
Module: TOOLS | Last Updated: 2026-07-09