Learn R Programming

pracma (version 1.8.6)

trigPoly: Trigonometric Polynomial

Description

Computes the trigonometric coefficients.

Usage

trigPoly(x, m)

Arguments

x
data from t=0 to t=2*(n-1)*pi/n.
m
degree of trigonometric regression.

Value

  • Coefficients as a list with components a0, a, and b.

Details

Compute the coefficients of the trigonometric series of degree m, $$a_0 + \sum_k(a_k \cos(k t) + b_k \sin(k t))$$ by applying orthogonality relations.

References

Fausett, L. V. (2007). Applied Numerical Analysis Using Matlab. Second edition, Prentice Hall.

See Also

trigApprox

Examples

Run this code
# 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)

# 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()

Run the code above in your browser using DataLab