Qu

delay

Builtin index · Signal processing

result = delay(x, n)

Input: x, n · Output: result

What it is

x: a vector or Signal; n: a whole number of samples, positional or named (delay(x, samples = 4)).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = delay(x, n)
x vector or Signalx: a vector or Signal.
n numbern: a whole number of samples, positional or named (delay(x, samples = 4)).
result Signal
Returns the SAME length as x, shifted later by n with the vacated head zero-filled and whatever runs off the end dropped. A negative n advances instead (drops from the head, zero-pads the tail); abs(n) >= length(x) is all zeros rather than an error. A Signal keeps its Fs — moving samples along the time axis does not change how fast they were taken.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

v = [1, 2, 3, 4, 5]
print("{delay(v, 2)}")     # [0, 0, 1, 2, 3]

print("{delay(v, -2)}")    # [3, 4, 5, 0, 0]

output
[0, 0, 1, 2, 3]
[3, 4, 5, 0, 0]

from signal-processing

How it works

delay(x, n) — shift x later along its own time axis by n samples, zero-filling the vacated head and dropping whatever falls off the end, so the result is the SAME length as the input. That is what a fixed-size buffer actually does, and keeping the length is what lets x + delay(x, 4) (a comb/echo, the obvious first use) line up at all — a version that returned a longer vector could not be added to its own input without the caller trimming it first. A negative n advances instead (drops from the head, zero-pads the tail), and |n| >= length(x) is all zeros rather than an error: shifting a buffer clear out of its own window has a perfectly well-defined answer. A Signal keeps its fs — moving samples along the time axis does not change how fast they were taken.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.