I noticed in the source code that there's a UAna that just does the domain change (Flip). That's exactly what was needed; no implementation change necessary. :)

Corrected example:
SinOsc s => Flip f =^ AutoCorr c => blackhole;
440 => s.freq;
1024 => f.size;
f.size()::samp => now;
c.upchuck();
Plot plot;
"autocorrelation of 440 hz, 1024 samples" => plot.title;
plot.plot(c.fvals());
100::ms => now;


On Thu, Jul 23, 2020 at 11:14 PM Curtis Ullerich <curtullerich@gmail.com> wrote:
I believe I found the bug. I sent a pull request with the fix and a lengthy description. xcorr_fft is taking the FFT of the input, but the upstream unit of the XCorr/AutoCorr UAnae is already required to be a UAna (so, it's already an FFT).

On Tue, Jul 21, 2020 at 1:07 AM Curtis Ullerich <curtullerich@gmail.com> wrote:
As a preamble, I'll note that I posted a question on chuck-dev about AutoCorr/XCorr always crashing for me. This patch seems to fix that.

That said, I don't understand the results I get from AutoCorr. For periodic inputs, I expect to see periodicity in the output. For small FFT sample sizes, I see the expected peak at 0, and at large sample sizes I see a second peak at the end of the window. See example plots at 128 and 4096. That second peak is correlated with the window size, not the input frequency.

Thanks to Mario for his gnuplot wrapper that captured those plots.

Here's the plotting code if anyone would like to repro:
SinOsc s => FFT fft =^ AutoCorr c => blackhole;
4400 => s.freq;
128 => fft.size;
300::ms => now;
c.upchuck();
Plot plot;
"autocorrelation of 4400 hz, 128 samples" => plot.title;
plot.plot(c.fvals());
200::ms => now;

Should I be using AutoCorr differently? Am I looking at the power spectrum or something, and not the correlation vector like I think I am? My current understanding comes from reading uana_extract.cpp many times with references like this.

Thanks,
Curtis