trigPoly: Trigonometric Polynomial

Description Usage Arguments Details Value Note References See Also Examples

View source: R/trigregress.R

Description

Computes the trigonometric coefficients.

Usage

1
trigPoly(x, m)

Arguments

x

data from t=0 to t=2*(n-1)*pi/n.

m

degree of trigonometric regression.

Details

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.

Value

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

Note

For irregular spaced data or data not covering the whole period, use standard regression techniques, see examples.

References

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

See Also

trigApprox

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 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)

pracma documentation built on Nov. 21, 2017, 3:01 p.m.