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
Here's a link to the simulink manual page describing this: http://www.mathworks.com/help/toolbox/simulink/slref/derivative.html
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)