I don't know exactly, no. You'd have to do some research - it's all standard FFT stuff.
I'm not convinced by your averaging at all, but hey, if it works for you...
If you really want a better result, average the entire array after the FFT, and do your calculations on that. If you know you have one single frequency then you can even get a more accurate idea of the frequency by looking at the relative size of the FFT peaks, eg:
// exactly that frequency
0,0,0,0,0,255,0,0,0,0,0
// halfway between two frequencies
0,0,0,0,0,128,128,0,0,0,0,0
// nearer the first frequency than the next one
0,0,0,0,0,192,64,0,0,0,0
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I don't know exactly, no. You'd have to do some research - it's all standard FFT stuff.
I'm not convinced by your averaging at all, but hey, if it works for you...
If you really want a better result, average the entire array after the FFT, and do your calculations on that. If you know you have one single frequency then you can even get a more accurate idea of the frequency by looking at the relative size of the FFT peaks, eg: