Qu

spectral_entropy

Builtin index · Signal processing

result = spectral_entropy(x, [nfft=256], [hop=nfft/2])

Input: x, nfft, hop · Output: result

What it is

x: a length-N real vector. nfft/hop (optional numbers): STFT frame size/hop as in stft.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = spectral_entropy(x, [nfft=256], [hop=nfft/2])
x vectorx: a length-N real vector.
nfft number, optional (default 256)nfft/hop (optional numbers): STFT frame size/hop as in stft.
hop number, optional (default nfft/2)nfft/hop (optional numbers): STFT frame size/hop as in stft.
num_frames —one value per STFT frame
Returns a vector of length num_frames (one value per STFT frame), each the Shannon entropy of that frame's normalized power spectrum, scaled to [0, 1]: low when energy concentrates in a few bins (a clean tone), high when spread across many (broadband noise).

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

  h = spectral_entropy(emg_signal, 256, 128)
  print("mean spectral entropy: {mean(h)}")

from numerics-dsp

How it works

spectral_entropy(x, [nfft=256], [hop=nfft/2]) — the Shannon entropy of each stft frame's normalized power spectrum, scaled to [0, 1]: low when a frame's energy concentrates in a few frequency bins (a clean tone), high when it's spread across many (broadband noise, or a complex/mixed signal).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.