Other processing

Other signal processing methods are available in StructuralVibration.jl.

1 Detrending

Detrending is the process of removing trends from a signal. This is useful when you want to analyze the fluctuations around a trend. The detrend function can be used to remove linear or polynomial trends from a signal.

1.1 API

detrend


detrend(t, y, order = 1, bp = [])

Detrend a signal y with respect to time t using a polynomial of order order.

Inputs

  • t: Time vector

  • y: Signal to be detrended

  • order: Order of the polynomial (default is 1)

  • bp: Breakpoints for the polynomial (default is empty)

Output

  • y_detrended: Detrended signal

Notes

order can be a vector if the trend is different over the segments defined by the breakpoints bp.

The breakpoints bp are the points where the polynomial order changes. If bp is empty, a single polynomial is fitted to the entire signal.

1.2 Example

# Signal 1
x1 = -0.5:0.01:0.5
y1 = @. sin(π*x1) + 0.25
y1_const = detrend(x1, y1, 0)
y1_lin = detrend(x1, y1, 1)

# Signal 2
x2 = 0:0.1:20
y2 = @. 3sin(x2) + x2
y2_const = detrend(x2, y2, 0)
y2_lin = detrend(x2, y2, 1)

2 Gradient

The gradient of a signal is the rate of change of the signal with respect to time. Julia [] has a lot of packages for computing the gradient of a signal. The gradient function in StructuralVibration.jl is a simple helper function built around the gradient function in Interpolations.jl.

2.1 API

gradient


gradient(f::Vector{Real}, t; method = :cubic)
gradient(f::Matrix{Real}, t; method = :cubic, dims = 1)

Compute the gradient of a function f at points t.

Inputs

  • f: Function values

  • t: Points at which to evaluate the gradient

  • method: Interpolation method

    • :linear: Linear interpolation

    • :cubic: Cubic spline interpolation (default)

  • dims: Dimension along which to compute the gradient

    • 1: Rows (default)

    • 2: Columns

Output

  • df: Gradient of the vector f at points t

Note

If method is :cubic, t must be an AbstractRange.

2.2 Example

# Signal
x = LinRange(0., 3π, 100)
y = sin.(x)

# True gradient
dy = cos.(x)

# Estimated gradient
dy_approx = gradient(y, x)

Note

Being based on interpolation, gradient is not robust against noise. For robust gradient estimation, you can compute the gradient of the signal denoised by the denoising function by using one of the numerous Julia differentiation packages if the signal is smooth enough (at least class \(C^\2\)). If the latter condition is not satisfied, you can for instance use NoiseRobustDifferentiation.jl, which implements the Total variation regularized numerical differentiation method1 .

Footnotes

  1. R. Chartrand. “Numerical differentiation of noisy, nonsmooth data”. ISRN Applied Mathematics, vol. 2011, 164564, 2011.↩︎