dsplib 1.1.0
C++ DSP library for MATLAB-like coding
Loading...
Searching...
No Matches
detector.h
1#pragma once
2
3#include <optional>
4#include <memory>
5
6#include <dsplib/array.h>
7
8namespace dsplib {
9
10class PreambleDetectorImpl;
11
12// Preamble signal detector (only complex signal)
13//
14// Equivalent Matlab formula:
15// function [res] = detector(x, h)
16// nh = length(h);
17// corr = filter(conj(h) / (nh * rms(h)), 1, x);
18// pagg = filter(ones(1, nh) / nh, 1, abs(x).^2);
19// res = sqrt((abs(corr) .^ 2) ./ pagg);
20//TODO: add real type implementation
22{
23public:
24 explicit PreambleDetector(span_cmplx h, real_t threshold = 0.5);
25
26 PreambleDetector(const PreambleDetector&) = delete;
27
28 struct Result
29 {
30 int offset{0};
32 real_t score{0};
33 };
34
35 //TODO: add bypass mode
36 //length of the 'sig' must be a multiple of 'frame_len()'
37 std::optional<Result> process(span_cmplx x);
38
39 std::optional<Result> operator()(span_cmplx x) {
40 return this->process(x);
41 }
42
43 [[nodiscard]] int frame_len() const noexcept;
44
45 void reset();
46
47private:
48 std::shared_ptr<PreambleDetectorImpl> _d;
49};
50
51} // namespace dsplib
Definition detector.h:22
Definition span.h:295
Definition detector.h:29
arr_cmplx preamble
aligned preamble signal (todo: left/right pad)
Definition detector.h:31
real_t score
detected peak level (>=threshold)
Definition detector.h:32
int offset
index of preamble end + 1 (relative to the input signal)
Definition detector.h:30