Learn R Programming

Momocs (version 0.1-03)

Outline: efourier: Elliptical Fourier Analysis core functions.

Description

These functions provide facilities for elliptical Fourier analysis. efourier computes Fourier coefficients from a set of coordinates; efourier.i calculates a shape given a set of Fourier coefficients computed with efourier; efourier.shape calculates a "Fourier elliptical shape" given Fourier coefficients (see Details) ; efourier.norm normalizes Fourier coefficients for rotation, tranlation, size and orientation of the first ellipse.

Usage

efourier(coo, nb.h = 32, smooth.it = 0)
efourier.i(ef, nb.h, nb.pts = 300)
efourier.shape(an, bn, cn, dn, nb.h, nb.pts=80, alpha=2, plot=TRUE)
efourier.norm(ef, start = FALSE)

Arguments

coo
A list or a matrix of coordinates.
nb.h
integer. The number of harmonics to use
smooth.it
integer. The number of smoothing iterations to perform.
nb.pts
integer. The number of points to calculate.
ef
list. A list containing $a_n$, $b_n$, $c_n$ and $d_n$ Fourier coefficients, such as returned by efourier.
an
numeric. The $a_n$ Fourier coefficients on which to calculate a shape.
bn
numeric. The $b_n$ Fourier coefficients on which to calculate a shape.
cn
numeric. The $c_n$ Fourier coefficients on which to calculate a shape.
dn
numeric. The $d_n$ Fourier coefficients on which to calculate a shape.
alpha
numeric. The power coefficient associated with the (usually decreasing) amplitude of the Fourier coefficients (see Details).
plot
logical. Whether to plot or not the shape.
start
logical. Whether to conserve the position of the first point of the outline.

Value

  • anvector of $A_{1->n}$ harmonic coefficients.
  • bnvector of B_{1->n} harmonic coefficients.
  • cnvector of C_{1->n} harmonic coefficients.
  • dnvector of D_{1->n} harmonic coefficients.
  • aoao Harmonic coefficient.
  • coco Harmonic coefficient.
  • xvector of x-coordinates.
  • yvector of y-coordinates.
  • sizeMagnitude of the semi-major axis of the first fitting ellipse.
  • thetaAngle, in radians, between the starting point and the semi-major axis of the first fitting ellipse.
  • psiOrientation of the first fitting ellipse.
  • Avector of numeric A_{1->n} normalized harmonic coefficients.
  • Bvector of numeric B_{1->n} normalized harmonic coefficients.
  • Cvector of numeric C_{1->n} normalized harmonic coefficients.
  • Dvector of numeric D_{1->n} normalized harmonic coefficients.
  • lnefA list with A, B, C and D concatenated in a vector that may be convenient for some uses.

Details

These functions and their mathematical background detailed below are here detailed to ease their use in new methods but are used internally by methods on Coo-objects. Elliptic Fourier analysis and normalization are calculated as follows. Let $T$ be the perimeter of a given closed outline, here considered as the period of the signal. One sets $\omega = 2\pi/T$ to be the pulse. Then, the curvilinear abscissa, $t$ varies from $0$ to $T$. One can express $x(t)$ and $y(t)$ as: $$x(t) = \frac{a_0}{2}+\sum\limits_{n=1}^{+\infty} a_n\cos n\omega t + b_n\sin n\omega t$$ with $$a_n = \frac{2}{T}+ \int\limits_{0}^{T} x(t)\cos (n\omega t) \mathrm{d} t$$ $$b_n = \frac{2}{T}+ \int\limits_{0}^{T} x(t)\sin (n\omega t) \mathrm{d} t$$ similarly, $$y(t) = \frac{c_0}{2}+\sum\limits_{n=1}^{+\infty} c_n\cos n\omega t + d_n\sin n\omega t$$ with $$c_n = \frac{2}{T}+ \int\limits_{0}^{T} y(t)\cos (n\omega t) \mathrm{d} t$$ $$d_n = \frac{2}{T}+ \int\limits_{0}^{T} y(t)\sin (n\omega t) \mathrm{d} t$$ Since the outline contains a $k$ finite number of points, one can therefore calculate discrete estimators for every harmonic coefficient of the $n^{th}$ harmonics: $$a_n=\frac{T}{2\pi^2n^2}\sum\limits_{p=1}^k \frac{\Delta x_p}{\Delta t_p}(\cos\frac{2\pi nt_p}{T}-\cos\frac{2\pi nt_{p-1}}{T})$$ $$b_n=\frac{T}{2\pi^2n^2}\sum\limits_{p=1}^k \frac{\Delta x_p}{\Delta t_p}(\sin\frac{2\pi nt_p}{T}-\sin\frac{2\pi nt_{p-1}}{T})$$ $\Delta x_1=x_1-x_k$ and $c_n$ and $d_n$ are calculated similarly. $a_0$ and $c_0$ correspond to the estimate of the coordinates of the centroid of original outline and are estimated by: $$a_0=\frac{2}{T}\sum\limits_{i=1}^p x_i$$ and $$c_0=\frac{2}{T}\sum\limits_{i=1}^p y_i$$ Intuitively, for all positive integers $n$, the sum of a cosine curve and a sine curve represent the $n^{th}$ harmonic content of the $x$ and $y$ projections of the $k$-edged polygon, and for any $n$, these two curves define an ellipse in the plane. Ferson and colleagues noticed that in the "time" it takes the $n^{th}$ harmonic to traverse its ellipse $n$ times, the $(n+1)^{th}$ harmonic has traversed its own ellipse $n+1$ times. The reconstruction of the original polygon is done by vector adding these ellipses for all harmonics, which echoes astronomical Ptolemy's epicycles (see Ptolemy), and the reconstruction obtained from $N$ harmonics is the best possible fit in a least-squares sense. efourier.shape can be used to draw "elliptical Fourier shapes" by specifying nb.h and alpha. The coefficients are then sampled in an uniform distribution $(-\pi ; \pi)$ and this amplitude is then divided by $harmonic_rank^alpha$. If alpha is lower than 1, consecutive coefficients will thus increase.

References

Claude, J. (2008) Morphometrics with R, Use R! series, Springer 316 pp. Ferson S, Rohlf FJ, Koehn RK. 1985. Measuring shape variation of two-dimensional outlines. Systematic Biology 34: 59-68.

See Also

Ptolemy for an implementation of the Ptolemaic ellipses.

Examples

Run this code
data(bot)
q <- (efourier(bot@coo[[1]]))
efourier.i(q) # equivalent to efourier.shape(q$an, q$bn, q$cn, q$dn)
efourier.norm(q)
efourier.shape(nb.h=5, alpha=1.2)
efourier.shape(nb.h=12, alpha=0.9)

Run the code above in your browser using DataLab