I understand that when you have a Laplace function, you can do a bilinear or forward/backward Euler substitution for $s$ to phrase it in terms of $z^{-1}$. In a typical filter, $z^{-1}$ represents the input to the filter delayed by one sample.

But what about if it's something that's not really meant to be a filter? Ie. Something that's not really meant to get an input?

eg. Let's say you have the equation, which comes from work using the differentiation theory for Laplace transforms:

enter image description here

Where V=velocity, m=mass, v0= initial velocity, and R=impedance.

This can be phrased in terms of time as:

enter image description here

I understand how to use the time based version. You can simply run a timer from time 0 and add the sampling period to it each sample, and put that timer in for "t" to get the output each sample.

But what about the Laplace version? If you tried to sub in say a backward Euler $s=(1−z^{−1})/T$, what does $z^{-1}$ represent?

$V(z) = (m * v0) / (m * [(1−z^{−1})/T] + (2 * R))$

What now is $z^{-1}$? From a coding standpoint, what do I put into this equation for $z^{-1}$? ie. What do you delay by one sample and put back into the equation here?

ie. If you were writing this equation in C++, what would you write for the $z^{-1}$? Thanks.

Edit: I appreciate the answers but I think they're missing what I'm looking for so please let me rephrase:

I can code the simple time based equation like this:

velocity = v0 * exp ((-2 * R * timer)/mass);
timer = timer + (1/sampleRate);

And it will output velocity appropriately at each sample.

I am asking, how would I write some basic code to do the same with the z equation? I cannot understand what variable or data to put in for $z^{-1}$.

s = (1-z_1)/T;
velocity = (m * v0) / ((m * s) + (2*R));

Now in this code, what exactly is z_1?

Thanks again.

  • $\begingroup$ I tried to answer this at this link- does this help you? dsp.stackexchange.com/questions/31830/… $\endgroup$ – Dan Boschen Dec 21 '19 at 16:43
  • $\begingroup$ Thanks Dan. I'm sure if I understood all that I wouldn't have this question, but that's a bit over my head, and my question is quite specific. I'm specifically wondering, in an equation like that, if I'm coding it in C++, WHAT EXACTLY do I put in for $z^{-1}$? $z^{-1}$ is a sample delay. But what do I delay by one sample and put in the equation to get an appropriate output? $\endgroup$ – mike Dec 21 '19 at 16:53
  • $\begingroup$ @DanBoschen I added a bit of C++ code to clarify my question exactly. Can you perhaps help? This is driving me crazy. Thanks again. I am learning for whatever it's worth. $\endgroup$ – mike Dec 21 '19 at 17:33
  • $\begingroup$ I get it-- I think Matt answered it clearly, take a closer look at his answer. v[n] is your current result and v[n-1] would be the result you last had before you iterated. Does that makes sense now? $\endgroup$ – Dan Boschen Dec 21 '19 at 17:34
  • $\begingroup$ In that case is it: z_1 = velocity; s = (1-z_1)/T; velocity = (m * v0) / ((m * s) + (2*R)); That looks messy in one line, but the idea is I am just using the already established velocity from the prior sample for z_1, then recalculating it from this. I thought I tried that and it didn't work. If that's right I'll go try it again. $\endgroup$ – mike Dec 21 '19 at 17:37

The $\mathcal{Z}$-transform expression corresponds to a difference equation which can be solved for $v[n]$, the velocity at sample $n$. From


you get


So the delay operates on the samples $v[n]$. You just choose an initial condition (e.g., $v[-1]=0$), and you can solve the difference equation $(2)$ for $v[n]$, $n\ge 0$.

EDIT: In reaction to your edited question, I would like to ask you to think about the Laplace transform $V(s)$. What would you put in for $s$? The answer is "nothing", it's just an equation that can be solved for the desired transform $V(s)$, which can then be transformed back to the time domain. Of course, you can replace $s$ by $j\omega$ (in case the imaginary axis is inside the region of convergence), and analyze the frequency behavior of the function. The same is true for the $\mathcal{Z}$-transform: set $z=e^{j\omega}$ to obtain the frequency response. But often you just use the Laplace transform and the $\mathcal{Z}$-transform in order to solve differential (difference) equations.

  • $\begingroup$ Thanks Matt. I understand better now. So I can't use equation 1 directly to get my velocity. I need to process it into equation 2 which I can then use. Can you clarify how you got from equation 1 to equation 2? $\endgroup$ – mike Dec 21 '19 at 17:54
  • $\begingroup$ @mike: It's just like the equation for $V(s)$, you can't directly use it to compute $v(t)$; you need to transform it back to the time domain. As for obtaining the difference equation $(2)$, just multiply both sides of $(1)$ by the denominator on the RHS and note that multiplication with $z^{-1}$ corresponds to a delay of one sample in the time domain. $\endgroup$ – Matt L. Dec 21 '19 at 17:59
  • $\begingroup$ Perfect thanks. I understand and reproduced your derivation. So you basically need to get rid of your $z^{-1}$ terms and have something in terms of [n-1] as you showed to get something you can use. Okay. Thanks $\endgroup$ – mike Dec 21 '19 at 18:28
  • $\begingroup$ @mike: that's right. $\endgroup$ – Matt L. Dec 21 '19 at 18:28

In the context of digial signal signal processing, the variable $z^{-1}$ stands for a single sample delay. And more generally, the variable $z^{-d}$ stands for a delay of $d$ samples, for $d$ positive integer. (or an advance of $d$ samples when $d<0$).

Whether it's an input signal such as $x[n-1]$ or an delayed output such as $y[n-2]$, or just a filter impulse response $h[n+3]$ delayed for some reason, or an expression involving a sum of multiple samples in time like an FIR impulse response $g[n] = b_0\delta[n] + b1\delta[n-1] + b_2 \delta[n-3] $.

All these signals will have a corresponding Z-domain expression as $z^{-1}X(z)$, $z^{-2}Y(z)$, $z^{3}H(z)$, and $G(z) = b_0 + b_1 z^{-1} + b_2 z^{-2}$ respectively.

  • $\begingroup$ Thanks, but I'm not sure that answers my question which is specific. I understand that $z^{-1}$ represents a single delay sample. I am asking, specifically in that equation, if I am coding it say in C++, what do I actually put in for $z^{-1}$? WHAT am I supposed to delay by one sample and put into the equation? $\endgroup$ – mike Dec 21 '19 at 16:50
  • $\begingroup$ it represents the previous sample of the array that it multiplies.. $\endgroup$ – Fat32 Dec 21 '19 at 16:54
  • $\begingroup$ Thanks but I don't understand what that means in this context, and that's my problem. Could you demonstrate how you would write that with a few lines of code? It's just supposed to output velocity over time. You can see how the time based equation works and as I said I understand that well enough. The z-based equation should work the same way. There's nothing to delay by a sample and put into it that I can figure out. $\endgroup$ – mike Dec 21 '19 at 16:57
  • $\begingroup$ When calculating a new output, you use the previous output. If it helps you think about it, use variable names such as output and previous. $\endgroup$ – Justme Dec 21 '19 at 17:02
  • $\begingroup$ Thanks @Justme, I reworded my question a bit to add some code to visualize. Can you clarify what the z_1 would equal there? $\endgroup$ – mike Dec 21 '19 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.