Description Usage Arguments Details Value See Also Examples
Computes half wavelengths and their positions and amplitude from a sine-like waveform based on either peak-to-trough or internodal distance.
1 2 3 4 5 6 7 8 9 10 |
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 |
character; the smoothing method when 'fit=TRUE', either 'loess' or 'spline'. See 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.
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, resptively. 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.
'zeros': x value where y crosses zero. Returns NA if 'method=p2t'.
'wave.begin': x value where each half wave begins.
'wave.end': x value where each half wave ends.
'begin.index': x index of where each half wave begins.
'end.index': x index of where each half wave ends.
'wave': numeric name of each wave.
'l': the length of each half wave.
'amp1': If method is set to 'p2t' this is the begin amplitude. If "method='zeros'", this is the maximum absolute amplitude between internodes.
'amp2': If method is set to 'p2t', this is the end amplitude. If "method='zeros' value is NA.
'pos1': If method is set to 'p2t', the x position of begin amplitude for each half wave and identical to 'begin'. If "method='zeros'", the position of maximum absolute amplitude between the internodes.
'pos2': If method is set to 'p2t', the x position of end amplitude for each half wave and identical to 'end'. If "method='zeros'", value is NA
If 'method="zeros"' and 'fit=TRUE', these values reflect the predicted, more dense data as determined by smoothing
, smooth
, and dens
.
features
, loess
, smooth.spline
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.