fourier: Fourier Series Components

View source: R/fourier.R

fourierR Documentation

Fourier Series Components

Description

Compute sine and cosine terms for describing annual or daily variations.

Usage

fourier(x, k.max = 1)

Arguments

x

a numeric vector where one unit specifies the period. See Details. Missing values are permitted.

k.max

the maximum number of paired sine and cosine terms specifying the order of the Fourier series.

Details

The argument x can be expressed as decimal time, either annual or diel; or it can be an object of class "Date," "POSIXct," or "POSIXlt" in which case it will be converted to annual decimal time using the dectime function.

Value

A matrix of the sine and cosine terms corresponding to the value—two terms are computed for each value of k from 1 to k.max: sine(k 2 pi x) and cosine(k 2 pi x). The value of k.max is included as an attribute.

Note

Water-quality data commonly follow a sinusoidal variation throughout a yearly cycle. A Fourier series of order one to three is generally enough to adequately describe that variation for many constituents.

See Also

dectime

Examples


# compute the sine and cosine terms for quarters of 2002
fourier(2002 + (0:3)/4)
#           sin(k=1)      cos(k=1) 
# [1,]  3.54692e-014  1.00000e+000
# [2,]  1.00000e+000  7.08886e-013
# [3,] -3.65749e-013 -1.00000e+000
# [4,] -1.00000e+000 -3.78606e-013
# attr(, "k.max"):
# [1] 1
# Compare to 2 cycles per year:
fourier(2002 + (0:3)/4, 2)
#            sin(k=1)      cos(k=1)     sin(k=2) cos(k=2)
#[ 1,]  3.546924e-14  1.000000e+00 7.093848e-14        1
# [2,]  1.000000e+00  7.088855e-13 1.417771e-12       -1
# [3,] -3.657492e-13 -1.000000e+00 7.314983e-13        1
# [4,] -1.000000e+00 -3.786056e-13 7.572112e-13       -1
# attr(,"k.max")
# [1] 2


USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.