Spectral Flux

Overview

spectral_flux is the level of the part of a signal above a cutoff frequency. It is a High Pass Filter followed by a Peak Envelope Follower: the level jumps at once and releases over a window.

A pick or a pluck puts broadband energy into that band, and a string ringing on keeps little of it, so the band’s level jumps at an attack and falls away as the note sustains. Compared with its own recent past by a delta_gate, that jump marks an attack from the spectrum of the signal. The block gives the level only; the threshold, and what counts as an attack, are the user’s.

The full-band level and the spectral flux of a plucked low E
Figure 1. A plucked low E, and spectral_flux(3 kHz, 50 ms). At the pluck, the band above 3 kHz is 17 dB below the full-band level. 100 ms later it is 26 dB below, and a second later 32 dB below, while the full-band level has dropped 11 dB. A delta_gate of 12 dB on the flux fires once, at the pluck.

The high-pass is a second-order Butterworth biquad (Q 0.707), 12 dB per octave. The follower’s window is its release: an SMA-equivalent span, about two time constants, as for the Peak Envelope Follower.

Include

#include <q/fx/spectral_flux.hpp>

Declaration

struct spectral_flux
{
   using follower = peak_envelope_follower;

               spectral_flux(
                  frequency cutoff, duration window, float sps);

   float       operator()(float s);
   float       operator()() const;
};

Expressions

Notation

sf, a, b

Objects of type spectral_flux.

f

Object of type frequency, the cutoff.

w

Object of type duration, the follower’s release.

sps

Floating point value representing samples per second.

s

Floating point value for the input sample.

Constructors and Assignment

Expression Semantics

spectral_flux(f, w, sps)

Construct a spectral_flux given f (cutoff), w (release) and sps (samples per second).

spectral_flux(sf)

Copy construct a spectral_flux from sf.

a = b

Assign b to a.

C++ brace initialization may also be used.

Function Call

Expression Semantics Return Type

sf(s)

Process the input sample s and return the level of the band above the cutoff.

float

sf()

Get the latest level.

float

Type Definitions

Expression Semantics Type

spectral_flux::follower

Get the envelope follower type.

peak_envelope_follower

Example

Detect a pick in the input samples in, at sps samples per second, by the band above 3 kHz rising 12 dB against about 20 ms ago. The monostable and the edge make one event per pick, as on the Delta Gate page:

#include <q/fx/delta_gate.hpp>    // For delta_gate
#include <q/fx/monostable.hpp>    // For monostable
#include <q/fx/edge.hpp>          // For rising_edge

namespace q = cycfi::q;
using namespace q::literals;

auto flux = q::spectral_flux{3_kHz, 50_ms, sps};          (1)
auto rise = q::delta_gate{12_dB, 20_ms, sps};
auto hold = q::monostable{100_ms, sps};
auto edge = q::rising_edge{};

for (auto s : in)
{
   bool pick = edge(hold(rise(flux(s))));                 (2)
}
1 Construct a spectral_flux on the band above 3 kHz, with a 50 ms release.
2 Process the sample, and pass the level of the band to the delta gate. pick is true once per pick.