Part II: Classical Signal Processing and Feature Engineering
Chapter 8: Feature Engineering and Dimensionality Reduction

Statistical, shape, and entropy features

"The mean tells me where the signal lives. The kurtosis tells me whether it is hiding a knife behind its back."

A Distribution-Minded AI Agent

The Big Picture

The time-domain features of Section 8.1 describe a window sample by sample, and the spectral features of Section 8.2 describe it frequency by frequency. This section takes a third view: forget the order of the samples for a moment and ask what the distribution of values looks like, what geometric shape the waveform traces, and how much irregularity or predictability it carries. These three families (statistical moments, shape descriptors, and entropy or complexity measures) are cheap, interpretable, and often the single most discriminative columns in a sensor feature table. A bearing that is starting to fail does not change its mean vibration; it changes the kurtosis. A patient sliding into arrhythmia does not change average heart rate first; the entropy of the beat-to-beat interval collapses. This section shows you what each family measures, why it works, and how to compute it without fooling yourself.

This section leans on the probability and estimation background from Chapter 4: moments, quantiles, and the idea that a finite window is a noisy estimator of an underlying distribution. If those terms feel shaky, skim that chapter first. Everything here is computed on a fixed analysis window, the same windowing discipline you have used throughout the chapter.

Statistical moments: the distribution as a fingerprint

Treat the \(N\) samples in a window as draws from a distribution and summarize that distribution with its moments. The first two are familiar: the mean \(\mu\) and the variance \(\sigma^2\). The interesting discrimination usually lives in the standardized third and fourth moments. Skewness measures asymmetry, and kurtosis measures how heavy the tails are relative to a Gaussian:

$$\text{skew} = \frac{1}{N}\sum_{i=1}^{N}\left(\frac{x_i-\mu}{\sigma}\right)^{3}, \qquad \text{kurt} = \frac{1}{N}\sum_{i=1}^{N}\left(\frac{x_i-\mu}{\sigma}\right)^{4}.$$

Why do these matter for sensors? Because a great many fault and event signatures are impulsive: they leave the bulk of the signal unchanged but inject rare, large excursions. Kurtosis is exquisitely sensitive to exactly those rare large values, since the deviations are raised to the fourth power. A healthy rotating machine produces near-Gaussian vibration with kurtosis close to 3; the first pits on a bearing race add sharp periodic impacts that push kurtosis to 5, 8, or higher long before the RMS energy moves. Skewness catches asymmetry: a photoplethysmography pulse has a steep upstroke and a slow decay, so its skew is a stable shape marker used in the wearable cardiovascular work of Chapter 30. Beyond moments, distribution-free quantiles (median, interquartile range, the 5th and 95th percentiles) give robust location and spread that a single outlier cannot wreck, which is why they pair so well with the heavy-tailed moments.

Key Insight: Order-Invariance Is a Feature and a Bug

Statistical, shape, and entropy features (with the exception of the ordinal entropies below) are computed on the histogram of values, so they are invariant to where in the window an event happened. That invariance is a gift for classification: a footstep in the first half or the second half of a window produces the same kurtosis, giving you built-in shift tolerance for free. It is also a trap: two signals with identical histograms but wildly different temporal structure (a slow ramp versus the same values shuffled into noise) are indistinguishable to a moment. That is precisely the blind spot entropy and complexity features exist to cover, and why you almost never ship moments alone.

Shape features: the geometry of the waveform

Shape features describe the form of the waveform or of its value histogram, often as dimensionless ratios that survive changes in sensor gain and units. The crest factor, the ratio of peak amplitude to RMS, quantifies how "peaky" a signal is: a pure sine sits at \(\sqrt{2}\approx 1.41\), while an impulsive fault signal climbs well above it. Related dimensionless ratios (the shape factor, impulse factor, and clearance factor) are staples of vibration diagnostics because they cancel out the operating amplitude and isolate waveform form:

$$\text{crest} = \frac{\max_i |x_i|}{\sqrt{\tfrac{1}{N}\sum_i x_i^2}}, \qquad \text{shape} = \frac{\sqrt{\tfrac{1}{N}\sum_i x_i^2}}{\tfrac{1}{N}\sum_i |x_i|}.$$

Other shape descriptors work on the trace itself rather than the histogram: the peak-to-peak span, the number and prominence of local maxima, the total length of the curve (its arc length, a proxy for roughness), and the area under the rectified signal. For a signal with a natural morphology, the biosignal world leans hard on these: an electrocardiogram beat is described by the width, amplitude, and slope of its QRS complex, features that carry straight into the cardiac models of Chapter 29. The common thread is that shape features encode what a cycle looks like, independent of how loud it is, which is exactly the invariance a robust classifier wants.

Entropy and complexity: how predictable is the signal?

Entropy features answer a question the moments cannot: given the recent past, how surprised are you by the next sample? A perfectly periodic signal is maximally predictable and scores low entropy; broadband noise is maximally surprising and scores high; and, importantly, many physiological and mechanical systems lose complexity as they fail or age, landing somewhere in between. Several definitions matter in practice. Spectral entropy treats the normalized power spectrum as a probability distribution and computes its Shannon entropy, measuring whether energy is concentrated in a few tones (low entropy) or spread across the band (high entropy). Sample entropy and approximate entropy measure temporal regularity by asking how often short patterns of length \(m\) that match within a tolerance \(r\) still match when extended to length \(m+1\). Permutation entropy is the cheap, robust favorite: it looks at the ordinal pattern (the rank order) of each short window of samples and computes the Shannon entropy of how often each pattern appears.

For a length-\(m\) ordinal pattern \(\pi\) occurring with relative frequency \(p(\pi)\), permutation entropy is simply

$$H_{\text{perm}} = -\sum_{\pi} p(\pi)\,\log p(\pi),$$

normalized by \(\log(m!)\) to land in \([0,1]\). Because it depends only on the order of values and not their magnitudes, permutation entropy is nearly immune to sensor drift, slow baseline wander, and monotone gain changes, the failure modes that plague raw amplitude features. Entropy features are the workhorses of the anomaly and change detectors in Chapter 12, where a sudden drop in regularity is the first sign that a monitored system has left its normal regime.

import numpy as np
from scipy.stats import skew, kurtosis
from math import factorial, log
from itertools import permutations

def permutation_entropy(x, m=3, tau=1):
    """Normalized permutation entropy of a 1-D signal."""
    patterns = {}
    for i in range(len(x) - (m - 1) * tau):
        window = x[i:i + m * tau:tau]
        order = tuple(np.argsort(window))     # the ordinal pattern
        patterns[order] = patterns.get(order, 0) + 1
    counts = np.array(list(patterns.values()), dtype=float)
    p = counts / counts.sum()
    H = -(p * np.log(p)).sum()
    return H / log(factorial(m))              # in [0, 1]

fs = 2000
t = np.arange(0, 1.0, 1 / fs)
healthy = np.sin(2 * np.pi * 50 * t) + 0.05 * np.random.randn(t.size)
impacts = 3.0 * (np.random.rand(t.size) < 0.01)      # rare sharp spikes
faulty  = healthy + impacts

for name, sig in [("healthy", healthy), ("faulty", faulty)]:
    print(f"{name:8s} kurtosis={kurtosis(sig)+3:5.2f} "
          f"skew={skew(sig):+5.2f} Hperm={permutation_entropy(sig):.3f}")
Computing three complementary features on a clean tone and the same tone with rare impulsive spikes. The impacts barely move the mean or the tone, but kurtosis jumps sharply while permutation entropy rises as the ordinal patterns become less regular. Run it to see the fault separate on features that RMS energy alone would miss.

The code above makes the division of labor concrete. Kurtosis fires on the impulsive spikes because of the fourth-power weighting; permutation entropy responds to the loss of clean periodic structure; and the two disagree in informative ways on other fault types, which is exactly why you compute all three rather than betting on one.

Practical Example: Reading Kurtosis Off a Gearbox in a Wind Turbine

A condition-monitoring team instrumented the gearbox of a utility-scale wind turbine with a single accelerometer sampled at 25 kHz. The turbine runs across a huge range of wind speeds, so raw RMS vibration swings by an order of magnitude through a normal day and makes a poor alarm. The team instead tracked kurtosis and crest factor on ten-second windows. These dimensionless features stayed flat near their healthy baseline regardless of load, because they measure waveform shape, not amplitude. When a bearing on the high-speed shaft began to spall, the periodic micro-impacts pushed kurtosis from roughly 3 to above 7 over two weeks, while permutation entropy on the same windows dipped as the impacts imposed a repeating structure. The alarm fired on the shape and complexity features together, weeks before any amplitude threshold would have tripped, feeding directly into the remaining-useful-life estimators of Chapter 36.

Right Tool: Do Not Hand-Roll the Entropies

A correct, fast sample entropy or multiscale permutation entropy with proper edge handling, tie-breaking, and vectorized pattern counting is easily 40 to 60 lines and a magnet for off-by-one bugs. The antropy library gives you the whole family in one line each:

import antropy as ant
h_perm = ant.perm_entropy(faulty, normalize=True)
h_spec = ant.spectral_entropy(faulty, sf=fs, method="welch", normalize=True)
h_samp = ant.sample_entropy(faulty)

The library owns the pattern counting, the spectral estimation, and the numerically safe logs. You still own the two choices no library can make for you: the embedding dimension \(m\) and the window length, both of which must match the timescale of the phenomenon you are hunting. Pick those; delegate the arithmetic.

Three validated entropy features in three lines with antropy, replacing roughly 40 to 60 lines of error-prone hand-written pattern counting and spectral estimation.

Computing them without self-deception

Three cautions keep these features from lying. First, moments and entropies are estimators: on a short window, kurtosis and sample entropy have large variance, so a single window can look alarming purely by chance. Aggregate over several windows or lengthen the window when the phenomenon allows. Second, scale sensitivity cuts both ways. Amplitude-based features (variance, peak-to-peak) demand that you fix calibration and units, while ordinal features (permutation entropy) and dimensionless ratios (crest factor) shrug off gain changes; choose deliberately based on whether your sensor's gain is trustworthy. Third, and most important for machine learning, these features are computed per window and then fed to a model, so any normalization statistics (feature means and standard deviations) must be fit on the training split only. Fitting a scaler on the whole dataset leaks test information and inflates your accuracy, exactly the trap the leakage-safe pipeline of Chapter 5 is built to prevent.

Exercise

Using the synthetic healthy and faulty signals from the code block: (1) Sweep the impact probability from 0.001 to 0.05 and plot kurtosis and permutation entropy against it; identify which feature separates fault from healthy earliest. (2) Multiply the whole faulty signal by 10 and recompute all three features; explain which change and which do not, and why. (3) Shuffle the samples of faulty randomly and recompute kurtosis, crest factor, and permutation entropy; explain why two of them are unchanged and one collapses.

Self-Check

  1. Two windows have identical mean, variance, and kurtosis but very different behavior over time. Which family of features in this section would tell them apart, and why can moments not?
  2. Why is crest factor often a better rotating-machine alarm than RMS when the operating load varies constantly?
  3. Why is permutation entropy nearly immune to slow sensor drift, while raw variance is not?

What's Next

In Section 8.4, we stop computing features one function at a time and reach for curated libraries. Tools like tsfresh and catch22 compute hundreds of statistical, shape, spectral, and entropy features in a single call, complete with automated relevance filtering, turning the hand-built columns of this section into an industrial feature factory.