# Generate data with linear trend and seasonal component
t <- seq(0, 10, length.out = 200)
X <- matrix(2 + 0.5 * t + sin(2 * pi * t / 2), nrow = 1)
fd <- fdata(X, argvals = t)
# Detrend with linear method
fd_detrended <- detrend(fd, method = "linear")
# Now estimate period on detrended data
period <- estimate.period(fd_detrended)
print(period$period) # Should be close to 2
# Get both trend and detrended data
result <- detrend(fd, method = "linear", return_trend = TRUE)
# plot(result$trend) # Shows the linear trend
Run the code above in your browser using DataLab