tomwalters@0: /* tomwalters@0: Autocorrelation function using FFT routines adapted from routines given in tomwalters@0: Numerical Recipes. tomwalters@0: The routine acf() uses an fft to compute the array of lagged products tomwalters@0: which is the autocovariance function. An optional normalization (dividing tomwalters@0: each coefficient by the zeroth coefficient) produces the autocorrelation tomwalters@0: function, (and this is then scaled up to the range [0-1000]). tomwalters@0: tomwalters@0: The output framewidth is the given maximum acf lag, which must not be tomwalters@0: greater than the input framewidth. tomwalters@0: tomwalters@0: Padding with zeroes is recommended to counter end-effects (See NR, p416). tomwalters@0: It is also necessary since: tomwalters@0: 1) framesize + padding must be a power of two (sample points at given rate). tomwalters@0: 2) max possible acf lag = ( framesize + padding ) / 2 tomwalters@0: tomwalters@0: Each input frame is padded with zeroes so that it is at least twice the tomwalters@0: required max acf lag, and is also a power of 2. tomwalters@0: This is because the fft method is "radix-2", and because the output acf is tomwalters@0: symmetrical so that just half the points are unique. tomwalters@0: Therefore each input frame is padded with zeroes to the next power of 2 tomwalters@0: larger than either the input framewidth, or twice the required max acf lag, tomwalters@0: (whichever is the larger). tomwalters@0: tomwalters@0: If necessary, extra padding can be enforced using the padding option to tomwalters@0: add extra zeroes, padding to a larger power of 2. tomwalters@0: The amount of extra padding is "exponential", expanding the basic size to: tomwalters@0: ( framesize + padding ) * 2**n tomwalters@0: where the padding option is n. tomwalters@0: (n=0 by default, so that no extra padding is added. When n=1 then padding is tomwalters@0: added to double the size, and when n=2 the size is quadrupled, etc.). tomwalters@0: tomwalters@0: Frames are selected from the input stream using the "frames" option, tomwalters@0: which has syntax: [[-]frame=a[-b]]. Input frames are numbered 1,2,... tomwalters@0: For example: tomwalters@0: frame=a Select just the a'th frame. tomwalters@0: frame=a-b Select frames from the a'th to b'th inclusive. tomwalters@0: The strings "min" and "max" can be used as specifiers, meaning eg: tomwalters@0: frame=min Select the first frame. tomwalters@0: frame=max Select the last frame. tomwalters@0: frame=a-max Select frames from the a'th to the last inclusive. tomwalters@0: frame=min-b Select frames from the first to the b'th inclusive. tomwalters@0: The default selects all frames, (ie frame=min-max). tomwalters@0: tomwalters@0: Other options (set using