findZeroCrossing: Find zero crossing

Description Usage Arguments Details Value Examples

View source: R/utilities_soundgen.R

Description

Internal soundgen function.

Usage

1
findZeroCrossing(ampl, location)

Arguments

ampl

a vector of amplitudes oscillating around zero, such as a sound waveform

location

the index indicating the desired location of a zero crossing

Details

findZeroCrossing looks for the last negative point before a zero crossing as close as possible to the specified location. Since this is primarily intended for joining waveforms without a click, this function only looks at upward segments of a waveform (see example).

Value

Returns the index of the last negative value before zero crossing closest to specified location.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
ampl = sin(1:100/2)
plot(ampl, type = 'b')
lines(1:100, rep(0,100), lty = 2)
zc = vector()
for (i in 1:length(ampl)){
  zc[i] = soundgen:::findZeroCrossing (ampl, i)
  # find zc closest to each of 100 points
}
for (z in unique(zc)){
  points(z, ampl[z], col = 'red', pch = 17)
  # only on upward segments
}
zc # see which zc is closest to each point

soundgen documentation built on Oct. 4, 2018, 9:04 a.m.