SidWizPlus icon indicating copy to clipboard operation
SidWizPlus copied to clipboard

Add autocorrelation based trigger

Open maxim-zhao opened this issue 7 years ago • 4 comments

From @maxim-zhao on October 18, 2018 6:6

Copied from original issue: maxim-zhao/SidWiz#2

maxim-zhao avatar Oct 26 '18 19:10 maxim-zhao

I develop ovgenpy, a related program based around an advanced correlation-based trigger. The main algorithm is located at:

https://github.com/jimbo1qaz/ovgenpy/blob/master/ovgenpy/triggers.py#L154

  • It correlates windowed audio with an internal windowed buffer, then picks the peak (np.argmax, https://github.com/jimbo1qaz/ovgenpy/blob/master/ovgenpy/triggers.py#L283 ).
  • I have a description at https://github.com/jimbo1qaz/ovgenpy/wiki/Correlation-Trigger
  • Demos at https://www.youtube.com/user/MrJimbo1qaz/videos

It only uses autocorrelation to adjust windowing, not to prioritize jumping by multiples of the period. But I hope to use the period someday (prioritize jumping by even multiples of the period to avoid octave errors).

If you port this algorithm to sidwizplus, I may be able to retire ovgenpy (which has graphing performance issues and doesn't have a gui yet).

nyanpasu64 avatar Nov 19 '18 01:11 nyanpasu64

My issue is that my mathematical grasp is not great :) I've implemented a dumb brute force correlation algorithm with weighting to prefer central matches, but it is not working (presumably due to a bug in the implementation, I'm working through it now) and horribly slow. I've read some stuff about faster autocorrelation computation via FFT but not managed to get far with it due to not having the maths to back it up - my last foray into this kind of thing was about 15 years ago and that mostly consisted of using statistical software to do the heavy lifting.

maxim-zhao avatar Nov 19 '18 08:11 maxim-zhao

I use numpy/scipy to do the fft correlation, I don't know how the fft works either ;)

To fix your trigger, you could use my unit tests (test_trigger and test_trigger_stride are good, and you can use my wave files too).

https://github.com/jimbo1qaz/ovgenpy/blob/master/tests/test_trigger.py#L39

nyanpasu64 avatar Nov 19 '18 11:11 nyanpasu64

I think there are some issues with the way I'm doing it - admittedly, I'm trying to start with the basics, which may explain the issues:

  • Rectangular windowing means I'm going to have difficulty on frequency changes - applying a bell curve to the input data will presumably help there, although I also see it recommended against in the context for FFTs for autocorrelation measurement
  • Comparing only to the previous window means the alignment can easily drift over time, and the goal here is to (somewhat) have a rock-solid alignment point
  • I'm not doing FFT at all, which is partly why it's slow

I suspect the answers to a lot of this lie in what you've one already,

maxim-zhao avatar Nov 19 '18 19:11 maxim-zhao