Incorporated external C function for calculating derivative (taking cell periodicity in account)