Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Decomposition

  • There are various regimes for signal decomposition.

  • Examples:

    • Fast Fourier Transform (FFT)

    • Wavelets

    • Linear components

  • Motviation:

    • Trend discovery

    • Low-pass/high-pass filter

    • Exploratory data analysis

Fast Fourier Transform

FFT history and application

  • An important workhorse in signal processing.

  • Can be traced back to Carl Friedrich Gauss on Discrete Fourier Transforms from 1805.

  • Major milestone in 1965 by James Cooley and John Tukey regarding speed of computations and applications in detecting Soviet nuclear bomb tests.

  • Used in anything from mathematical speed-ups, via video and music compression, modern signal processing in Wi-Fi, 5G, etc. to finance.

FFT function

  • Wikipedia: A Fourier Transform is a transform that converts a function into a form that describes the frequencies present in the original function.

  • scipy.fft: Fourier analysis is a method for expressing a function as a sum of periodic components, and for recovering the signal from those components.

Xk=∑n=0N−1xnei2πkn/N    k=0,...,N−1X_k = \sum_{n=0}^{N-1} x_n e^{i2 \pi kn/N} ~~~~ k = 0, ..., N-1
  • Here, k is the index of a signal, X, and N is its length. xnx_n is a coefficient to be fitted.

<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>

Direct Cosine Transform (DCT)

  • FFT with real valued data.

  • For real numbered signals, the definition above can be exchanged with a version based on the cosine or sine functions.

  • There are theoretically 8+8 “types”, 4+4 of which are implemented in SciPy, and various choices for normalisation.

  • Type I DCT (Direct Cosine Transform) as implemented in SciPy:

yk=x0+(−1)kxN−1+2∑n=1N−2xncos(πknN−1))y_k = x_0 + (-1)^k x_{N-1} + 2 \sum_{n=1}^{N-2} x_n cos (\frac{\pi k n}{N-1}))
  • yky_k is the kk-th part of the signal, NN is the length, xnx_n is the nn-th coefficient.

  • Coefficient signs indicate flip of the base cosines, magnitudes indicate scaling.

  • n indicates the number of half cosine cycles, i.e., even n means full cycles (see plot below), maximum frequency of n/2.

  • Quicker than FFT and guarantees real valued frequency domain.

<Figure size 640x480 with 1 Axes>
<Figure size 700x500 with 3 Axes>
Sampling of the time axis: 200.0 Hz
<Figure size 700x400 with 2 Axes>

FFT filtering

  • We can apply the FFT to analyse the frequencies present or to filter the signal.

    • Filtering here means that some frequencies are removed from the signal.

  • Typical filters are:

    • Low-pass filter: Remove high frequencies, e.g., noise or short-term changes, focusing on trends or slowly changing signals.

    • High-pass filter: Remove low frequencies, e.g., trends or baselines, focusing on rapid changes or anomalies.

<Figure size 640x480 with 1 Axes>
<Figure size 700x200 with 1 Axes>
<Figure size 700x300 with 1 Axes>
<Figure size 700x300 with 1 Axes>

Overlay cosines on signal

<Figure size 700x300 with 1 Axes>
yk=x0+(−1)kxN−1+2∑n=1N−2xncos(πknN−1))y_k = x_0 + (-1)^k x_{N-1} + 2 \sum_{n=1}^{N-2} x_n cos (\frac{\pi k n}{N-1}))

Linear decomposition

  • Various forms of linear models can be used for decomposition, each having different focus or optimality criteria, e.g.:

Seasonal-Trend decomposition using LOESS (STL)

  • STL takes a (time) series as input together with an estimate of period length.

  • Output are:

    • A trend along the series (T).

    • A seasonal signal which may evolve along the series (S).

    • A residual (R).

    • Additive: X = T + S + R

    • (Multiplicative: X = T * S * R)

  • Additional parameters:

    • Length of smoothers for trend and season (high number = less change).

    • Use weighting of samples for robustness (allow more individual deviation from trend/season).

Fitting:

  • Simplified, one can think of STL is being fitted one component at a time.

    • Smooth the series to estimate the trend,
      T=fsmooth,T(X)T = f_{smooth,T}(X).

    • Subtract the trend from the series,
      XS+R=X−TX_{S+R} = X - T.

    • Average across seasons with sliding window (LOESS) to estimate the season,
      S=fsmooth,S(XS+R)S = f_{smooth,S}(X_{S+R}).

    • Subtract the trend and season from the signal to estimate the residual,
      R=X−T−SR = X - T - S

  • In practice, this happens within a loop where observations are given weights which are updated iteratively based on previous fits.

(2820, 2)
Loading...
<Figure size 700x200 with 1 Axes>
np.float64(134.0)
<Figure size 640x480 with 4 Axes>
Loading...
<Figure size 640x480 with 4 Axes>

Excercise

  • Force the period to change less.

  • Extract the trend and plot it as a function of time.

  • Indicate the date of maximum number of conceptions (~9 months before birth), assuming the year is cyclic.

Multiple seasonalities

  • If a there is more than one phenomenon with a cyclic behaviour, multiple seasonalities can be found through Multiple Seasonal-Trend decomposition using LOESS (MSTL).

  • The more complex model one applies, the higher the chances of overfitting!

  • Example at statsmodels.org

Principal Component Analysis (PCA)

  • For (time) series with multiple variables, PCA can give a first indication of structure and connection between variables.

  • Scores show paths of time points, loadings show how variables relate.

  • One PCA formulation for input data X\mathbf{X} with series as columns:

USV′=svd(X−Xˉ)\mathbf{U} \mathbf{S} \mathbf{V}' = svd(\mathbf{X}-\bar{\mathbf{X}})
T=US - scores\mathbf{T} = \mathbf{U} \mathbf{S} \text{ - scores}
P=V′ - loadings\mathbf{P} = \mathbf{V}' \text{ - loadings}

Beijing pollution data

This dataset is originally from UCI Machine Learning Repository and shows hourly measurements of weather at the US embassy in Bejing. Its columns are:

  1. No: row number

  2. year: year of data in this row

  3. month: month of data in this row

  4. day: day of data in this row

  5. hour: hour of data in this row

  6. pm2.5: PM2.5 concentration (μg/m3\mu g/m^3)

  7. DEWP: Dew Point (∘F^{\circ}F)

  8. TEMP: Temperature (∘F^{\circ}F)

  9. PRES: Pressure (hPa)

  10. cbwd: Combined wind direction

  11. Iws: Cumulated wind speed

  12. Is: Cumulated hours of snow

  13. Ir: Cumulated hours of rain

(43824, 12)
Loading...
Loading...
Loading...
<Figure size 400x400 with 1 Axes>
<Figure size 640x480 with 1 Axes>
<Figure size 400x400 with 1 Axes>
<Figure size 640x480 with 1 Axes>