Hello all!
Been playing with Arduino's for over two years now and this is my first post, so please don't berate me too much! Haha.
So, after some research for a project I am making, I needed a PDA (pitch detection algorithm) instead of an FFT (the quasi-harmonic frequency usually isn't the strongest!). I've settled on using the AMDF (autocorrelation mean difference function) and implementing it on a 16mhz atmeag328. Since I couldn't find any examples for my purpose I've built my own code specifically for a violin and its frequency range. I am trying to get the calculation intensive algorithm to move a little faster. Currently it processes at 56ms per AMDF. Any pointers would be greatly appreciated!
electric_violin_v3_byte.ino (10.3 KB)
Thats already looking really tight David, don't think there's much more performance to be squeezed out of it.
I have had mixed results by holding pointers to my arrays, and if indexing in a linear fashion (which you are), just pop the pointer in the loop.
This is usually quicker, but it depends on array data type, array size, platform, compiler etc etc.
May be worth a shot?
I think I understand what you are saying.
I have to hold the pointer because the first half of the AMDF is faster than the ADC interrupt. So i'd be stepping on my toes for the first half and then when the higher number of calculations for a longer delay come in which is slower than the ADC interrupt, the calculations would be okay. So I would get erroneous high frequency hits or misses.
But I guess, would a local variable be faster than a global variable? I am not completely intimate with the memory characteristic or what the compiler will do.
BTW, I shaved 4ms off the time by moving the loudness code into the update window if statement in the ISR. Didn't make sense to continuously update loudness when the MCU was still working on an older frame of samples.
I also just saw the new Arduino Zero (I've been living under a rock) and ill probably move in that direction because 8 bits just isn't hacking it for me.
I find it really difficult to profile and find hot spots on Arduino, could use arduino pins as profiler tags and connect a scope to find the intensive parts that need optimising.
Have you ruled out the raspberry pi? Cheaper than a zero, and has some serious performance.