1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use f64;
use Complex64;
use crateSAMPLE_RATE;
/// This function does various DSP operations on the `samples` vec
///
/// First it performs a hilbert transform, using the result to do a quadrature demod.
///
/// # Math behind the quadrature demod:
/// IQ samples = e^(iθ)
///
/// Z1 * Z2 = r1 * r2 * e^(i(θ1 + θ2)) (de moivre's theorem)
///
/// therefore
///
/// Z1 * conj(Z2) = r1 * r2 * e^(i(θ1 - θ2))
///
/// making
///
/// arg(Z1 * conj(Z2)) the phase difference between Z1 and Z2
///
/// This means that the principal argument of current sample times the conjugate
/// of the previous sample will equal the phase difference between the two,
/// which can be converted to a frequency reading by multiplying with:
///
/// SAMPLE_RATE / (2 * pi)
///
/// This means we can get a continuous frequency measurement over all the samples