# extract trend correctly, including most recent values

I'm looking to extract the trend of a signal.

i've tried two methods for now, polynomial regression, and wavelet denoising

both methods don't respect the computation of the last values (meaning the last values computed will not be the same if we compute a longer buffer containing new values).

is there a way, excluding FIR/IIR filters to extract a trend that stay consistent across all the values in time ?

matlab code is welcome if possible

here, with Matlab denoising, we can see most recent values aren't the same

thanks

• "extract trend correctly, including most recent values" This is a tough job. especially if the need is not fully clear: "last values computed will not be the same if we compute a longer buffer containing new values" Could you rephrase or state your question in more precise terms? – Laurent Duval Jun 25 '18 at 19:39
• Hi: If I understand your question correctly, you are saying that all the estimates ( at any time t ) change, when an observation is added to the end. If you use a kalman filtering approach , then this won't happen. A non-smoothed kalman filter estimate at time $t$, uses the data up until time $t$ so it won't be effected by adding data on to the end. Of course, that doesn't address the question of what model to implement as a KF. Since you're interested in the trend, one possibility is a local linear trend model. See Harvey (1990, blue book ) for an explanation of this model or google for it. – mark leeds Jun 25 '18 at 19:47
• Hi: The local linear trend model is explained on page 5 of this link. personal.vu.nl/s.j.koopman/documents/2011TSEweek1.pdf – mark leeds Jun 25 '18 at 19:50
• Laurent : as you can see on the picture, the red curve is above the black curve at sample 4200 in the top graph whereas the red curve is under the black curve in the bottom graph. I'd like to have the same red curve in both graphs – ion_one Jun 26 '18 at 7:53
• Hi: In case you look into my suggestion, I should mention that the local linear trend model can be viewed as an arima(0,2,2) which I think can be viewed as an FIR so my suggestion doesn't meet your criteria. And my apologies for any confusion. – mark leeds Jun 26 '18 at 14:21