the function call just partly work

If you've copied and posted the wrong code, why not post the actual code?

I don't really see the point of the for loop.
If you're only interested in the differences between adjacent samples, why store 100 of them?