Guys,

First of all, a little background information. I am a condition monitoring consultant. I have been self employed for 23 years and have been involved in CM for almost 30. I use FFT vibration analysis to monitor machine condition and diagnose faults. I have a client who wants a device which will continuously monitor a critical piece of his plant so I have designed an ADC shield for the MEGA2560 using an MCP3208 12 bit ADC as the built in 10 bit ADC does not offer sufficient resolution. I have the FFT side sorted.

I recently read this paper http://www.icmrt07.unina.it/Proceedings/Papers/A/84.pdf regarding using kurtosis as a tool for detecting bearing failure so I started looking for examples of how to calculate kurtosis. I came across this old thread kurtosis calculations on an analog signal - Programming Questions - Arduino Forum

So, in my code, I request a sample fftsample(p,KURTLEN,1); which will collect KURTLEN samples from channel p and store them in the array fft_input[] (the 1 in the call arguments is the step in this case puts data in every 1 bin whereas the fft routine expects real data in odd bins and imaginary in the even bins so the step would be 2)

The sampling rate is 2560hz which would give me a full size fft of 0-1280hz but in vibration analysis, we only use 200 , 400, 800 etc lines which gets rid of some aliasing. KURTLEN is defined as 1024 but again I welcome suggestions.

From the above thread, I have re-written some of the OP's code and put it in a function

```
float Kurtosis()
{
int i;
int total = 0;
int average = 0;
double sqDevSum = 0.00;
double sum= 0.00;
double kurtval=0.00;
double stDev4=0.00;
double denominator = 0.00;
double numerator = 0.00;
for (i=0; i < KURTLEN; i++)
total += fft_input[i];
average = total / KURTLEN;
for (int i=0; i < KURTLEN; i++)
fft_input[i] -= average;
for (int i=0; i < KURTLEN; i++)
sqDevSum += pow(fft_input[i], 2);
int stDev = sqrt(sqDevSum/KURTLEN);
int stDev4= pow(stDev, 4);
for (int i=0; i < KURTLEN; i++)
sum += = pow(fft_input[i], 4);
denominator = KURTLEN*stDev4;
numerator = sum;
kurtval = (numerator/denominator)-3;
return kurtval);
}
```

Now, let me add that I am not a mathematician - I struggle with this sort of thing but I can work through code and get the gist of what it is trying to do and hopefully in this case, I have it right but I'd like to ask anyone who understands these things better than me to look over the cade and comment. tmd3 and el_supremo, from the original thread, your comments would be very welcome.

Thank you to the OP, blwill428 who wrote the code.

Thanking you in advance for your kind assistance, Steve.