Skip to main content

Other processings

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 .

3 Amplitude of a signal

In vibration measurements, the amplitude of a signal \(x(t)\) (displacement, velocity or acceleration) can be defined in different ways:

  • Peak value: \(x_{peak} = \max(|x(t)|)\). It is often used for short-duration phenomena (e.g. shocks), but does not account for the time evolution of the vibration.

  • Peak-to-peak value: \(x_{p-p} = \max(x(t)) - \min(x(t))\). It is often used for displacement measurements, to be compared with a critical displacement.

  • Root mean square (RMS) value: \[ x_{RMS} = \sqrt{\frac{1}{T}\int_0^T x^2(t)\, dt} \] It is related to the vibratory energy and accounts for the time evolution of the signal.

3.1 API

peak_value


peak_value(x; dims = :)

Compute the peak value of a signal x.

The peak value is defined as:

x_peak = max(|x(t)|)

Inputs

  • x: Signal (displacement, velocity, acceleration, ...)

  • dims: Dimension along which the peak value is computed (default: all dimensions)

Output

  • x_peak: Peak value

Note

The peak value is often used to characterize short-duration phenomena (e.g. shocks), but it does not account for the time evolution of the vibration.

peak2peak


peak2peak(x; dims = :)

Compute the peak-to-peak value of a signal x.

The peak-to-peak value is defined as:

x_pp = max(x(t)) - min(x(t))

Inputs

  • x: Real signal (displacement, velocity, acceleration, ...)

  • dims: Dimension along which the peak-to-peak value is computed (default: all dimensions)

Output

  • x_pp: Peak-to-peak value

Note

The peak-to-peak value is often used for displacement measurements, to be compared with a critical displacement.

Example

julia> peak2peak([1., -3., 2.])
5.0

rms_value


rms_value(x; dims = :)

Compute the root mean square (RMS) value of a signal x.

The RMS value is defined as:

x_RMS = sqrt((1/T)∫₀ᵀ x²(t) dt)

For a sampled signal, it is computed as:

x_RMS = sqrt((1/N)∑ₙ |xₙ|²)

Inputs

  • x: Signal (displacement, velocity, acceleration, ...)

  • dims: Dimension along which the RMS value is computed (default: all dimensions)

Output

  • x_rms: RMS value

Note

The RMS value is related to the vibratory energy and accounts for the time evolution of the signal. ```

3.2 Example

# Signal
fs = 1000
t = (0:fs - 1)/fs
x = @. 2sin(2π*5t) + 0.5

# Amplitudes
x_peak = peak_value(x)
x_pp = peak2peak(x)
x_rms = rms_value(x)

x_peak, x_pp, x_rms

4 Phase unwrapping

The phase of a complex signal (FRF, spectrum, …) computed with angle is wrapped in the interval \((-\pi, \pi]\), which leads to artificial jumps of \(2\pi\). The unwrap_phase function removes these jumps to obtain a continuous phase.

Warning

The unwrapping must always be performed in radians. Converting the phase to degrees before unwrapping it leads to wrong results. To get the unwrapped phase in degrees, use the deg = true keyword argument.

4.1 API

unwrap_phase


unwrap_phase(x; dims = 1, deg = false)

Compute the unwrapped phase of a signal x.

The phase returned by angle is wrapped in the interval (-π, π]. This function removes the artificial 2π jumps to obtain a continuous phase.

Inputs

  • x: Signal

    • Complex signal (e.g. FRF, spectrum): the phase is first computed with angle

    • Real signal: x is assumed to be a wrapped phase expressed in radians

  • dims: Dimension along which the phase is unwrapped (default: 1, i.e. each column is considered as a channel)

  • deg: If true, the unwrapped phase is returned in degrees (default: false)

Output

  • ϕ: Unwrapped phase [rad or deg]

Notes

Common pitfalls avoided by this function:

  • The unwrapping is always performed in radians. Converting the phase to degrees before unwrapping it with a 2π range leads to wrong results.

  • For multichannel signals, the unwrapping is performed independently along dims, so that the channels are not mixed.

The unwrapping relies on the assumption that the phase difference between two successive samples is lower than π. If the frequency resolution is too coarse, the unwrapped phase may be wrong.

Example

julia> freq = 0:0.1:1;

julia> H = exp.(-im*10freq);

julia> unwrap_phase(H)[end]
-10.0

4.2 Example

# FRF of a delayed system
freq = 0:0.5:100
τ = 0.02
H = @. exp(-2im*π*freq*τ)

# Wrapped and unwrapped phases
ϕ_wrapped = rad2deg.(angle.(H))
ϕ_unwrapped = unwrap_phase(H, deg = true)

5 Decibel conversion

The to_dB function converts a signal to decibels with respect to a reference value. Two cases must be distinguished:

  • Amplitude (root-power) quantities (displacement, velocity, acceleration, pressure, FRF, RMS values, …): \[ L = 20 \log_{10}\left(\frac{|X|}{X_{ref}}\right) \]

  • Power (energy) quantities (squared amplitude, power, energy, PSD, autospectrum, …): \[ L = 10 \log_{10}\left(\frac{|X|}{X_{ref}}\right) \]

In both cases, \(X_{ref}\) is expressed in the same unit as \(X\). For a power quantity, the reference is therefore the square of the amplitude reference, so that both definitions lead to the same level.

Usual reference values can be obtained with the ref_dB function.

5.1 API

to_dB


to_dB(x, ref = 1.; type = :amplitude)

Convert a signal x to decibels (dB) with respect to the reference value ref.

Inputs

  • x: Signal to convert (scalar or array, real or complex)

  • ref: Reference value, expressed in the same unit as x (default: 1.)

  • type: Type of quantity contained in x

    • :amplitude (default): Root-power (field) quantity - displacement, velocity, acceleration, pressure, FRF, RMS values, ...

      L = 20 log₁₀(|x|/ref)

    • :power: Power (or energy) quantity - squared amplitude, power, energy, PSD, autospectrum, ...

      L = 10 log₁₀(|x|/ref)

Output

  • L: Level of x in dB

Notes

Both definitions give the same level for a given physical quantity, provided that ref is consistent with x. For a power quantity, ref must therefore be a power reference, i.e. the square of the amplitude reference (e.g. ref = (2e-5)^2 Pa² for a pressure autospectrum).

Usual reference values are given by ref_dB.

Null values of x give -Inf dB.

ref_dB


ref_dB(quantity::Symbol; type = :amplitude)

Return the usual reference value used to express a quantity in decibels (SI units).

Inputs

  • quantity: Type of physical quantity

    • :mobility: 1 m/s/N

    • :accelerance: 1 m/s²/N

    • :displacement: 1 pm = 1e-12 m

    • :velocity: 1 nm/s = 1e-9 m/s

    • :acceleration: 1 µm/s² = 1e-6 m/s²

    • :pressure: 20 µPa = 2e-5 Pa

  • type: Type of quantity to be converted (see to_dB)

    • :amplitude (default): Amplitude reference value

    • :power: Power reference value, i.e. the square of the amplitude reference value

Output

  • ref: Reference value

```

5.2 Example

# Acceleration amplitude of 1 mm/s² (ref = 1 µm/s²)
L_amp = to_dB(1e-3, 1e-6)

# Same quantity expressed as a power quantity (ref = (1 µm/s²)²)
L_pow = to_dB((1e-3)^2, (1e-6)^2, type = :power)

# Using the usual reference values
L_ref = to_dB(1e-3, ref_dB(:acceleration))

L_amp, L_pow, L_ref

Footnotes

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