wave: Compute wavelengths from a sine-like waveform

Description Usage Arguments Details Value See Also Examples

View source: R/kin.2d.R

Description

Computes full wavelengths and their positions and amplitude from a sine-like waveform based on either peak-to-peak, trough-to-trough, or internodal distance.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
wave(
  x,
  y,
  method = "zeros",
  zero.begin = TRUE,
  fit = TRUE,
  dens = 10,
  smooth = 0.1,
  smoothing = "loess"
)

Arguments

x

numeric; x position

y

numeric; y position

method

character; how waves should be found and classified, where it crosses zero/the internodal length ("zeros"), peak to peak ("p2p") or trough to trough ("t2t"). See Details.

zero.begin

logical; does wave begin at zero? Default is 'TRUE' and will help find waves beginning at first x,y values if y=0

fit

logical; if 'method="zeros"', should zeros be detected by a fitting operation. See Details.

dens

numeric; factor by which to increase the sample density used in fitting when 'method="zeros"'. See Details.

smooth

numeric; if smoothing is set to 'loess', 'span' parameter value for loess. If smoothing is set to 'spline' 'spar' parameter value for smooth.spline

smoothing

character; the smoothing method when 'fit=TRUE', either 'loess' or 'spline'. See Details.

Details

If 'method="p2p"' or 'method="t2t"', full waves are found using critical points (i.e., local maxima, the peaks or minima, the troughs) with features.

If 'method="zeros"' and 'fit=TRUE', zero crossings are determined by first increasing the sample density by a factor determined by dens. A more dense loess or smooth.spline model is then fit to the data and new y values predicted. Wave positions and lengths are determined based on these predicted values. This option should be useful when the sampling density of the waveform is relatively low and therefor detected wave positions and zero crossings (the internodes) may be rather coarse.

Value

A list with the following components:

method the method chosen to find full waves

names a data table with columns 'x', 'y', and 'wave' describing the x and y positions of the wave and a numeric name of each wave detected, respectively. If 'method="zeros"' and 'fit=TRUE', these values reflect the predicted, more dense data as determined by smoothing, smooth, and dens.

dat a data table describing each wave detected.

If 'method="zeros"' and 'fit=TRUE', these values reflect the predicted, more dense data as determined by smoothing,smooth, and dens.

See Also

features, loess, smooth.spline

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
require(ggplot2)
#Find length of the full waves
x <- seq(0,pi,0.01)
y <- sin(x^2*pi)

#zero method
w.z <- wave(x,y,method="zeros",smoothing="spline",smooth=0.1)

#plot wave with detected full waves using fitted 'zeros' method
p <- ggplot()+geom_point(aes(x=x,y=y))
p <- p+geom_line(data=w.z$names,aes(x=x,y=y,col=wave),alpha=0.4,size=3,inherit.aes=FALSE)
p+theme_classic()

#plot lambda as it varies with position

qplot(data=w.z$dat,x=pos1,y=l)

#trough-to-trough method
w.p <- wave(x,y,method="t2t")

qplot(data=w.p$names,x=x,y=y,col=wave)

trackter documentation built on April 19, 2021, 1:08 a.m.