Rob,

>>> Does it solve your problem now?

I have to try in practice in my application see if the result is acceptable.

In a "perfect" wind controller, I should be able to detect a gradual

*decrescendo*, that is the player blowing softer and softer to make the sound fade away gradually but I don't know how I would differentiate that from the slow decay that I see when I stop blowing altogether.

>>> Otherwise you might need the second derivative too.

By second derivative you mean something like:

`newderivative = oldvalue - newvalue ;`

secondderivative = oldderivative - newderivative ;

oldderivative = newderivative ; // Remembers the previous one

>>> Missing in the graph is the square wave, derived from the first derivative. Would make the picture complete.

Sorry, I did not include it because it does not show very well, But I am attaching it now. I am also attaching the actual Excel in case you are interested (the 8 periods moving average was calculated in the spreadsheeti itself).

>>> Maybe smoothing the original signal with a moving average is better than smoothing the derivative (should become smoother automatically).

I did not think about that because the actual signal seems clean enough but maybe a 2 or 4 period moving average of the signal will yield a clean derivative as well and be faster to show a true change

>>> seen this class -

http://arduino.cc/playground/Main/RunningAverage - ?

No, I haven't. It does look very useful.

My approach is very similar to yours in:

`long runningAverage(int M)`

which avoids the need for floating math.

with the difference that I use two distinct routines, one for initializing the array during setup() and one to update the actual running average from loop().

That has the advantage of eliminating

` if (count < LMSIZE) count++;`

so that the division is always by 16 (in my case) which could be replaced by a rightward 4 bit shift (though if I understand correctly, the compiler is smart enough to make the replacement).

Also, is:

` index = index % LMSIZE;`

More efficient than:

` index++ ;`

if (index >= LMSIZE) index = 0 ; // If LMSIZE is 16 index cannot be more than 15

I can post the code for my little functions if of interest (and if you'd like to comment on it)

Thanks again