halfwave: Compute half wavelengths from a sine-like waveform

Description Usage Arguments Details Value See Also Examples

View source: R/kin.2d.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
halfwave(
  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 half waves should be found and classified, where it crosses zero/the internodal length ("zeros") or peak to trough/trough to peak ("p2t"). 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="p2t"', half waves are found using critical points (i.e., local maxima and minima) with features. Detected half waves with this method can be either peak to trough or trough to peak.

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 half 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 half 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 have 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 half waves
x <- seq(0,pi,0.01)
y <- sin(x^2*pi)
qplot(x,y)

#zero method predicting zeros
w.z <- halfwave(x,y,method="zeros",fit=TRUE,smoothing="spline")

#plot waveform with detected half 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)

#peak-to-trough method
w.p <- halfwave(x,y,method="p2t")
qplot(data=w.p$names,x=x,y=y,col=wave)

ckenaley/trackter documentation built on Feb. 11, 2022, 6:43 a.m.