nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
spectral_metrics.hpp
Go to the documentation of this file.
1// toolboxes/signal/include/nk/signal/spectral_analysis/spectral_metrics.hpp
2//
3// Spectral measurement functions.
4
5#pragma once
6
7#include <memory_resource>
8#include <tuple>
9#include <nk/value/value.hpp>
10
11namespace nk::signal {
12
15
16
26
41 const Value &fs = Value::Empty,
42 const Value &freqrange = Value::Empty,
43 std::pmr::memory_resource *mr = nullptr);
44
54Value meanfreq(const Value &x, const Value &fs = Value::Empty,
55 std::pmr::memory_resource *mr = nullptr);
56
66Value medfreq(const Value &x, const Value &fs = Value::Empty,
67 std::pmr::memory_resource *mr = nullptr);
68
79Value enbw(const Value &window, const Value &fs = Value::Empty,
80 std::pmr::memory_resource *mr = nullptr);
81
99std::tuple<Value, Value, Value, Value>
100obw(const Value &x, const Value &fs = Value::Empty,
101 double p = 0.99,
102 std::pmr::memory_resource *mr = nullptr);
103
111Value powerbw(const Value &x, const Value &fs = Value::Empty,
112 std::pmr::memory_resource *mr = nullptr);
113
122 std::pmr::memory_resource *mr = nullptr);
123
134 std::pmr::memory_resource *mr = nullptr);
135
145 std::pmr::memory_resource *mr = nullptr);
146
155 std::pmr::memory_resource *mr = nullptr);
156
165 std::pmr::memory_resource *mr = nullptr);
166
167// ─────────────────────────────────────────────────────────────────────
168// Harmonic / SNR family
169//
170// All compute fundamental power and noise / harmonic power on the
171// periodogram, then return the ratio in dB. Default behaviour treats
172// the dominant peak (excluding DC) as the fundamental and uses N = 6
173// harmonics.
174// ─────────────────────────────────────────────────────────────────────
175
186Value snr(const Value &x, const Value &fs = Value::Empty,
187 std::pmr::memory_resource *mr = nullptr);
188
198Value sinad(const Value &x, const Value &fs = Value::Empty,
199 std::pmr::memory_resource *mr = nullptr);
200
210Value thd(const Value &x, const Value &fs = Value::Empty,
211 std::pmr::memory_resource *mr = nullptr);
212
222Value sfdr(const Value &x, const Value &fs = Value::Empty,
223 std::pmr::memory_resource *mr = nullptr);
224
225// ─────────────────────────────────────────────────────────────────────
226// Analytic-signal-based instantaneous metrics
227// ─────────────────────────────────────────────────────────────────────
228
240Value instfreq(const Value &x, const Value &fs = Value::Empty,
241 std::pmr::memory_resource *mr = nullptr);
242
253Value instbw(const Value &x, const Value &fs = Value::Empty,
254 std::pmr::memory_resource *mr = nullptr);
255
256
258} // namespace nk::signal
Core MATLAB-compatible multidimensional array and scalar value type.
Definition value.hpp:61
static const Value Empty
MATLAB-style empty matrix sentinel — a 0×0 DOUBLE value.
Definition value.hpp:136
Value instbw(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Instantaneous bandwidth.
Value thd(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Total harmonic distortion in dB.
Value spectralentropy(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Shannon entropy of the normalised PSD.
Value enbw(const Value &window, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Equivalent noise bandwidth of a window (b = enbw(window, fs)).
Value spectralflatness(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Spectral flatness: geomean(P) / mean(P).
Value sinad(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Signal-to-noise-and-distortion in dB.
Value bandpower(const Value &x, const Value &fs=Value::Empty, const Value &freqrange=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Power in a frequency band (p = bandpower(x, fs, freqrange)).
Value spectralcrest(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Spectral crest: max(P) / mean(P) (peakedness).
std::tuple< Value, Value, Value, Value > obw(const Value &x, const Value &fs=Value::Empty, double p=0.99, std::pmr::memory_resource *mr=nullptr)
Occupied bandwidth at fraction p of total power ([bw, flo, fhi, power] = obw(x, fs,...
Value instfreq(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Instantaneous frequency via Hilbert transform.
Value meanfreq(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Power-weighted mean frequency.
Value spectralkurtosis(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Kurtosis of the PSD treated as a frequency distribution.
Value powerbw(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
3-dB power bandwidth around the dominant peak.
Value sfdr(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Spurious-free dynamic range in dB.
Value snr(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Signal-to-noise ratio in dB.
Value medfreq(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Median frequency.
Value spectralskewness(const Value &x, const Value &fs=Value::Empty, std::pmr::memory_resource *mr=nullptr)
Skewness of the PSD treated as a frequency distribution.