spkit.total_variation

spkit.total_variation(x, normalise=False, method='npdiff', **kwargs)

Total Variation of a signal

\[ \begin{align}\begin{aligned}TV(x) = \sum_n |x_{n+1}-x_{n}|\\TV(x) = \sum |\frac{dx}{dt}|\end{aligned}\end{align} \]

Bounds

\[min \{ max(x) - min(x) \} \ge TV(x) \ge (n-1) \times min \{ max(x) - min(x) \} \]

where \(n=length(x)\)

Returns:
tv: float
  • Total Variation of x

References

Examples

#sp.total_variation
import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
x1, fs = sp.data.optical_sample(sample=1)
x2, fs = sp.data.optical_sample(sample=2)
tv_x1 = sp.total_variation(x1,normalise=False)
tv_x2 = sp.total_variation(x2,normalise=False)
print(f'TV(x1) = {tv_x1}')
print(f'TV(x2) = {tv_x2}')