Qu

diff

Builtin index · Collections & strings

result = diff(x)

Input: x · Output: result

What it is

x is a numeric Vec or Signal of length N.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = diff(x)
x Vec or Signalnot documented yet
result Signal
Returns the first difference (x[i+1] - x[i]), length N-1, same base type as x; a Signal input stays a Signal with the same Fs.

Examples

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

clean = zeros(200)
for i in 60 to 129
    clean[i] = 1.0
end for
noisy = clean + 0.15 * randn(200, seed = 3)

tv = tv_denoise(noisy, 0.3)
print("total variation {sum(abs(diff(noisy))):.1f} -> {sum(abs(diff(tv))):.1f}")
output
total variation 36.5 -> 2.5

from compressed-sensing