Qu

fill_missing

Builtin index · Noise

fill_missing(x, [method="linear"], [value=])

Input: x, method, value · Output: no output

What it is

x with the missing samples patched, same length, so a Signal keeps its Fs. method is a named string: "linear" (default), "previous"/"ffill", "next"/"bfill", "nearest", "mean", "median". value is a named number overriding all of them with a constant.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
fill_missing(x, [method="linear"], [value=])
x Signalx with the missing samples patched, same length, so a Signal keeps its Fs.
method string, optional (default "linear")method is a named string: "linear" (default), "previous"/"ffill", "next"/"bfill", "nearest", "mean", "median".
value number, optionalvalue is a named number overriding all of them with a constant.
not documented yet—

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

print(interpolate_nan([0, nan, nan, 30]))   # [0, 10, 20, 30]

print(interpolate_nan([0, 10, 20, nan]))    # [0, 10, 20, 20] -- holds, does not climb

print(fill_missing([1, nan, 9], method = "previous"))  # [1, 1, 9]

print(fill_missing([1, nan, 9], value = 0))            # [1, 0, 9]

print(find_missing([1, nan, 3]))                       # [1]

print(remove_nan([1, nan, 3]))                         # [1, 3]

output
[0, 10, 20, 30]
[0, 10, 20, 20]
[1, 1, 9]
[1, 0, 9]
[1]
[1, 3]

from noise

How it works

fill_missing(x, [method="linear"], [value=]) — patch the dropouts, keeping the length (and so a Signal's Fs). method: "linear" (default), "previous"/"ffill", "next"/ "bfill", "nearest", "mean", "median". value= overrides them all with a constant. interpolate_nan(x) is the same thing spelled for the one case that is overwhelmingly the common one -- it IS fill_missing(x, method="linear"), sharing the engine rather than being a second implementation, and is kept as its own name only because that is the operation people go looking for by name. The linear fill deliberately does NOT extrapolate at the ends (a gap with good data on one side only holds the nearest good sample). interp1 does extrapolate -- verified, not assumed: interp1([0,1,2,3], [0,10,20,30], 6) is 60 -- which is why it is not reused here unchanged. The two are answering different questions: interp1's caller asked for the model's value at a named point outside the data, while here nobody asked for anything and a trailing dropout is being patched so the next stage has something to work with. Extrapolating there turns a dropout into a trend, which is worse than a flat patch precisely because it looks like data.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.