# time derivative of discrete data in simulink

I'm implementing a program in Java that was delivered in Simulink. My expertise is limited, and I'm stuck on converting a derivative block.

The simulink code applies a du/dt block to the input data. I'm doing the following in my code:

du_dt = (signal[i] - signal[i-1])/time[i];


where signal is an array of data samples, and time is an array of elapsed time (in seconds) between sample i and sample i-1.

my java program is generating much larger derivative values than my simulink program. doing some digging, i see that the simulink man8al talks about the derivative definition as

$$y(k)=\frac{1}{\Delta t}(u(k)-u(k-1))$$

and taking the z-transform

$$\frac{Y(z)}{u(z)}=\frac{1-z^{-1}}{\Delta t}=\frac{z-1}{\Delta t\cdot z}$$

my undergrad in mathematics stops short of being able to understand what the z-transform is and how to translate it into code. any help?

EDIT

EDIT 2

As requested, here's the data of the Simulink output and mine:

0.0, 0.0
1211.4359554191567, 692.2491173823755
573.0790390610672, 859.6185585916019
346.12455869118764, 461.4994115882501
807.6239702794378, 634.5616909338439
230.74970579412505, 692.2491173823755
286.53951953053365, 401.1553273427467
519.1868380367816, 634.5616909338443
-288.43713224265656, 403.8119851397189
-57.307903906106624, 343.8474234366401
-173.06227934559388, 57.68742644853153

0   0
1.01133071339275    1.01133071339275
-1.38227619434410   -1.38227619434408
-1.43825420168704   -1.43825420168706
-0.640385232441365  -0.640385232441365
-0.157483736804270  -0.157483736804270
-1.01133071339275   -1.01133071339275
-2.92203612549265   -1.96668341944271
-3.77588310208105   1.68679338272849
-2.98846441805972   1.44870448691124
-2.96756384761120   -0.629934947217123


The first section is mine, the second is the simulink. The indices are aligned, the data is two-dimensional but the derivative is of each individual dimension (so it's like two separate data sets)

-
 What does i, signal[i], and time[i] represent? Are they scalar? Of what type (integer, rational, complex, etc)? And are they discrete or continuous? – user2468 Apr 1 '12 at 23:39 i is an integer index into the signal and time arrays; signal is an array of discrete signal samples, rational real numbers; time is an array of time elapsed between sample[i] and sample [i-1], in seconds. – kolosy Apr 1 '12 at 23:53 – user2468 Apr 1 '12 at 23:57 yes, i saw that before i came here. theoretically relevant, but definitely not what the simulink documentation is talking about – kolosy Apr 1 '12 at 23:58 Your arrays are in time domain. You do not need the discrete Laplace transform. The simulink page describes the discrete time derivative as (signal[i] - signal[i-1])/time[i]. Also, it describes the derivative in $z$-domain as (singal[z] - signal[z]/z)/time[z]. Your arrays are in time domain. – user2468 Apr 2 '12 at 0:03