Learn R Programming

phonTools (version 0.2-2.2)

fastacf: Fast Autocorrelation

Description

Compute the ACF of a signal.

Usage

fastacf  (signal, lag.max = length(signal), window = 'hann',
          show = TRUE, correct = FALSE)

Value

A dataframe with the following columns:

lag

Indicates the lag value.

acf

Indicates the ACF value at the lag.

Arguments

signal

The signal, a numeric vector.

lag.max

The maximum lag value to be returned.

window

The type of window to be applied to the signal. Uses the windowfunc() function in this package. For no window select 'rectangular'.

show

If TRUE, the results are plotted.

correct

If TRUE, the output is corrected based on the window length and the window function that is applied.

Author

Santiago Barreda <sbarreda@ucdavis.edu>

Details

The autocorrelation function is calculated using the inverse Fourier transform applied to the power spectrum. This leads to much faster calculation times than the acf() function included in the typical R installation. Corrections for window type and length are carried out as described in Boersma (1993).

References

Boersma, P., (1993). Accurate short-term analysis of the fundamental frequency and the harmonics-to-noise ratio of a sampled sound. Proc. Instit. Phon. Sci. 17: 97-110.

Examples

Run this code

## Uncomment and run the code below to see the speed advantage.
## Raising the n makes the difference even more pronounced.
#n = 25000
#system.time ({
#acf (rnorm (n), plot = F, lag.max = n)
#})

#system.time ({
#fastacf (rnorm (n), plot = F, lag.max = n)
#})

Run the code above in your browser using DataLab