How does fillgaps work?
3 views (last 30 days)
Show older comments
Hello!
I was wondering how https://www.mathworks.com/help/signal/ref/fillgaps.html works. As it is implied, fillgaps replaces any NaNs present in a signal x with estimates extrapolated from forward and reverse autoregressive fits of the remaining samples. As far as i know, an autoregressive model specifies that the output variable depends linearly on its own previous values and on a stochastic term. So, why it is written that forward values are also taken into account?
Is there an equation for the fillgaps command? As well as an explanation of its parameters?
Please, i really need an answer on this topic.
Thanks in advance!
Answers (1)
Ondrej Mokrý
on 16 Jan 2024
Consider a signal with only a single gap for simplicity. The function fillgaps takes the context prior to the gap (cropped to length maxlen, if this parameter is set), estimates an AR model for this context (the order of this model can also be set) and uses this model to predict (extrapolate) the missing samples one by one, given the linear dependence governed by the estimated coefficients of the AR model.
For a signal segment x and model order p, we can efficiently perform extrapolation of n samples (e.g., corresponding to length of the gap) as follows:
af = arburg(x, p); % length of the signal x has to be at least p+1
zf = filtic(1, af, flip(x(end-p+1:end)));
prediction = filter(1, af, zeros(1, n), zf); % produces the extrapolated segment of length n
To utilize also the samples coming after the gap, fillgaps repeats the same extrapolation procedure with flipped (reversed) version of this context after the gap. Clearly, this reverse extrapolation has to be flipped again to fit the original signal.
The forward and backward predictions are then linearly cross-faded to produce the final signal filled in the gap.
0 Comments
See Also
Categories
Find more on Signal Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!