set.seed(42)
t <- seq(0, 1, length.out = 50)
X <- matrix(0, 20, 50)
for (i in 1:20) X[i, ] <- sin(4 * pi * t) + rnorm(50, sd = 0.1)
fd <- fdata(X, argvals = t)
# Find optimal nbasis
cv_result <- fdata2basis_cv(fd, nbasis.range = 5:15, type = "fourier")
print(cv_result$optimal.nbasis)
Run the code above in your browser using DataLab