1
$\begingroup$

I have a picture in my head of a specific DSP operation, but I don't know what it's called or how to google for it. I'm pretty sure it's a fairly common operation, however I have no idea what to call it.

Consider a discrete event that occurs at time interval (Excuse the ascii art):

                          |
              |           |
x       |     |  |        |
     _  |  _  |  |  _  _  |  _  _
     0  1  2  3  4  5  6  7  8  9
                     t

What I have is two vectors descibing this waveform.

x = [2,3,2,4]
t = [1,3,4,7]

What I want to do, is 'latch' the most recent signal over time, like this:

                          |  |  |
              |           |  |  |
x       |  |  |  |  |  |  |  |  |
     _  |  |  |  |  |  |  |  |  |
     0  1  2  3  4  5  6  7  8  9
                     t

Which would produce this waveform:

x = [0,2,2,3,2,2,2,4,4,4]
t = [0,1,2,3,4,5,6,7,8,9]

In electrical terms, this would be a memory element which remembers the most recent signal received. It also would be some crude interpolate function, however all the interpolates I know about (linear, cubic) fill in the in-between with more complicated functions.

I'd like to recreate this behaviour in Matlab but don't know how to google for what I want. So what's this called?

$\endgroup$
  • $\begingroup$ This is trivial to implement: if the current sample is undefined, set its value to that of the previous. $\endgroup$ – Yves Daoust Aug 11 '16 at 14:23
1
$\begingroup$

I figured this out, it's called a Sample and Hold. The matlab page on it talks about how to implement one in matlab.

In summary, an interpolate function is used to create it. There are a couple of interpolate options, like "next", "previous" and "nearest". The "extrap" is needed to extrapolate the waveform for times 8 and 9. Continuing my example:

x     = [2,3,2,4]
t     = [1,3,4,7]
t_new = 1:9

x_new = interp1(t,x,t_new,"previous","extrap")

Produces

x_new =
     2   2   3   2   2   2   4   4   4
| improve this answer | |
$\endgroup$

Your Answer

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