soundpoints: calculates acoustic landmarks for whistled sounds from an...

Description Usage Arguments Value Warning Author(s) See Also Examples

View source: R/soundpoints.R

Description

each event in the sound file is represented by the same number of landmarks.

Usage

1
soundpoints(file.name, time.res, freq.res, passband, amplitude.cutoff, loudness.column, half.life, initial.amplitude, amplitude.threshold, var.columns, var.weights, n.landmarks)

Arguments

file.name

the location of a file in WAV format

time.res

the desired time resolution of the spectrogram

freq.res

the desired frequency resolution of the spectrogram – this will be converted to the nearest power of two, based upon the sample rate of the input file

passband

a two-element vector that defines the frequency range within the spectrogram that will contain the landmarks

amplitude.cutoff

the area under the peak at each instant of the spectrogram

loudness.column

the variable to use when separating signal vs. noise. see make.peaks

half.life

this tunes the sensitivity of the amplitude smoother. smaller values means the moving average is more sensitive to sudden changes in amplitude. a good starting guess for this parameter is the time from one element to the next.

initial.amplitude

the starting amplitude of the signal vs. noise smooth. Large values exclude more noise at the beginning

amplitude.threshold

peaks are only counted as signal if they exceed the moving average by at least this much. If you set it at -1, for example, everything at least 10 dB quieter than the moving average will be included.

var.columns

the columns of the frequency contour that will be included in the landmark analysis. see make.peaks.

var.weights

when calculating the difference between successive peaks, these are the weights of each of the var.columns. For example, you could include time, mean frequency, and mean amplitude as your variables, and set var.weights = 1/c(0.1,4000,Inf). This would cause the event detector to ignore amplitude and make a new event when successive peaks are separated by 0.1 seconds or 4 kiloHertz.

n.landmarks

the number of landmarks per event. Events that include fewer than n.landmarks peaks will be thrown out.

Value

file

the name of the audio file, without path information

spg

the spectrogram object showing the whole file

peaks

the frequency contour of the whole file

landmarks

a data frame with one row per event, holding envelope and landmark measurements (e.g. duration, mean time, time1, time2, etc.)

Warning

This function makes a spectrogram from the WHOLE file, so don't use it on long recordings!

Author(s)

Benjamin N. Taft ben.taft@landmarkacoustics.com

See Also

detect.events make.peaks smooth.average plot.spg landmark.plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (file.name, time.res, freq.res, passband, amplitude.cutoff, 
    loudness.column, half.life, initial.amplitude, amplitude.threshold, 
    var.columns, var.weights, n.landmarks) 
{
    spg <- spectrogram(file.name, time.res, freq.res)
    peaks <- make.peaks(spg, passband, amplitude.cutoff)
    peaks$smooth.amplitude <- smooth.average(peaks[, loudness.column], 
        get.time.res(spg), half.life, initial.amplitude)
    not.noise <- peaks[, loudness.column] > peaks$smooth.amplitude + 
        amplitude.threshold
    ids <- data.frame(event = rep(NA, nrow(peaks)), landmark = NA)
    ids$event[not.noise] = detect.events(peaks[not.noise, var.columns], 
        var.weights)
    ids$landmark[not.noise] <- assign.to.landmarks(ids$event[not.noise], 
        n.landmarks)
    no.smooth <- -ncol(peaks)
    landmarks <- aggregate(peaks[not.noise, no.smooth], list(event = ids$event[not.noise]), 
        mean)
    names(landmarks)[-1] <- paste("mean", names(landmarks)[-1], 
        sep = ".")
    landmarks$duration <- aggregate(peaks$time[not.noise], list(event = ids$event[not.noise]), 
        function(x) {
            diff(range(x))
        })$x
    for (j in 1:n.landmarks) {
        f <- not.noise & ids$landmark == j
        if (any(f)) {
            temp <- aggregate(peaks[f, no.smooth], list(event = ids$event[f]), 
                mean)
            names(temp)[-1] <- paste(names(temp)[-1], j, sep = ".")
            landmarks <- cbind(landmarks, temp[match(landmarks$event, 
                temp$event), -1])
        }
    }
    landmarks <- landmarks[is.finite(apply(landmarks, 1, sum)), 
        ]
    ix <- grep("time", names(landmarks))[-1]
    landmarks[, ix] <- landmarks[, ix] - landmarks$mean.time
    peaks$event <- ids$event
    peaks$landmark <- ids$landmark
    answer <- list(file = basename(file.name), spg = spg, peaks = peaks, 
        landmarks = landmarks)
    return(invisible(answer))
  }

landmarkacoustics/SoundPoints-R documentation built on May 29, 2019, 9:14 a.m.