Trigonometric Polynomial
Computes the trigonometric coefficients.
trigPoly(x, m)
x |
data from |
m |
degree of trigonometric regression. |
Compute the coefficients of the trigonometric series of degree m,
a_0 + ∑_k(a_k \cos(k t) + b_k \sin(k t))
by applying orthogonality relations.
Coefficients as a list with components a0, a, and b.
For irregular spaced data or data not covering the whole period, use standard regression techniques, see examples.
Fausett, L. V. (2007). Applied Numerical Analysis Using Matlab. Second edition, Prentice Hall.
# Data available only from 0 to pi/2
t <- seq(0, pi, len=7)
x <- 0.5 + 0.25*sin(t) + 1/3*cos(t) - 1/3*sin(2*t) - 0.25*cos(2*t)
# use standard regression techniques
A <- cbind(1, cos(t), sin(t), cos(2*t), sin(2*t))
ab <- qr.solve(A, x)
ab
# [1] 0.5000000 0.3333333 0.2500000 -0.2500000 -0.3333333
ts <- seq(0, 2*pi, length.out = 100)
xs <- ab[1] + ab[2]*cos(ts) +
ab[3]*sin(ts) + ab[4]*cos(2*ts) +ab[5]*sin(2*ts)
## Not run:
# plot to make sure
plot(t, x, col = "red", xlim=c(0, 2*pi), ylim=c(-2,2),
main = "Trigonometric Regression")
lines(ts, xs, col="blue")
grid()
## End(Not run)Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.