SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
sdrbase
dsp
fftcorr.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 F4EXB //
3
// written by Edouard Griffiths //
4
// //
5
// FFT based cross correlation //
6
// //
7
// See: http://liquidsdr.org/blog/pll-howto/ //
8
// Fixed filter registers saturation //
9
// Added order for PSK locking. This brilliant idea actually comes from this //
10
// post: https://www.dsprelated.com/showthread/comp.dsp/36356-1.php //
11
// //
12
// This program is free software; you can redistribute it and/or modify //
13
// it under the terms of the GNU General Public License as published by //
14
// the Free Software Foundation as version 3 of the License, or //
15
// (at your option) any later version. //
16
// //
17
// This program is distributed in the hope that it will be useful, //
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
20
// GNU General Public License V3 for more details. //
21
// //
22
// You should have received a copy of the GNU General Public License //
23
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
25
26
#include <algorithm>
27
#include "
fftcorr.h
"
28
29
void
fftcorr::init_fft
()
30
{
31
fftA
=
new
g_fft<float>
(
flen
);
32
fftB
=
new
g_fft<float>
(
flen
);
33
34
dataA
=
new
cmplx
[
flen
];
35
dataB
=
new
cmplx
[
flen
];
36
dataBj
=
new
cmplx
[
flen
];
37
dataP
=
new
cmplx
[
flen
];
38
39
std::fill(dataA, dataA+
flen
, 0);
40
std::fill(
dataB
,
dataB
+
flen
, 0);
41
42
inptrA
= 0;
43
inptrB
= 0;
44
outptr
= 0;
45
}
46
47
fftcorr::fftcorr
(
int
len) :
flen
(len),
flen2
(len>>1)
48
{
49
init_fft
();
50
}
51
52
fftcorr::~fftcorr
()
53
{
54
delete
fftA
;
55
delete
fftB
;
56
delete
[]
dataA
;
57
delete
[]
dataB
;
58
delete
[]
dataBj
;
59
delete
[]
dataP
;
60
}
61
62
int
fftcorr::run
(
const
cmplx
& inA,
const
cmplx
* inB,
cmplx
**out)
63
{
64
dataA
[
inptrA
++] = inA;
65
66
if
(inB) {
67
dataB
[
inptrB
++] = *inB;
68
}
69
70
if
(
inptrA
<
flen2
) {
71
return
0;
72
}
73
74
fftA
->
ComplexFFT
(
dataA
);
75
76
if
(inB) {
77
fftB
->
ComplexFFT
(
dataB
);
78
}
79
80
if
(inB) {
81
std::transform(
dataB
,
dataB
+
flen
,
dataBj
, [](
const
cmplx
& c) ->
cmplx
{
return
std::conj(c); });
82
}
else
{
83
std::transform(
dataA
,
dataA
+
flen
,
dataBj
, [](
const
cmplx
& c) ->
cmplx
{
return
std::conj(c); });
84
}
85
86
std::transform(
dataA
,
dataA
+
flen
,
dataBj
,
dataP
, [](
const
cmplx
& a,
const
cmplx
& b) ->
cmplx
{
return
a*b; });
87
88
fftA
->
InverseComplexFFT
(
dataP
);
89
90
std::fill(
dataA
,
dataA
+
flen
, 0);
91
inptrA
= 0;
92
93
if
(inB)
94
{
95
std::fill(
dataB
,
dataB
+
flen
, 0);
96
inptrB
= 0;
97
}
98
99
*out =
dataP
;
100
return
flen2
;
101
}
102
103
const
fftcorr::cmplx
&
fftcorr::run
(
const
cmplx
& inA,
const
cmplx
* inB)
104
{
105
cmplx
*dummy;
106
107
if
(
run
(inA, inB, &dummy)) {
108
outptr
= 0;
109
}
110
111
return
dataP
[
outptr
++];
112
}
fftcorr::dataBj
cmplx * dataBj
Definition:
fftcorr.h:50
fftcorr::inptrA
int inptrA
Definition:
fftcorr.h:52
fftcorr::flen2
int flen2
half FFT length
Definition:
fftcorr.h:45
g_fft::InverseComplexFFT
void InverseComplexFFT(std::complex< FFT_TYPE > *buf)
Definition:
gfft.h:3325
fftcorr.h
g_fft::ComplexFFT
void ComplexFFT(std::complex< FFT_TYPE > *buf)
Definition:
gfft.h:3309
fftcorr::flen
int flen
FFT length.
Definition:
fftcorr.h:44
fftcorr::~fftcorr
~fftcorr()
Definition:
fftcorr.cpp:52
fftcorr::cmplx
std::complex< float > cmplx
Definition:
fftcorr.h:35
fftcorr::fftA
g_fft< float > * fftA
Definition:
fftcorr.h:46
fftcorr::init_fft
void init_fft()
Definition:
fftcorr.cpp:29
fftcorr::dataA
cmplx * dataA
Definition:
fftcorr.h:48
g_fft< float >
fftcorr::fftB
g_fft< float > * fftB
Definition:
fftcorr.h:47
fftcorr::dataP
cmplx * dataP
Definition:
fftcorr.h:51
fftcorr::fftcorr
fftcorr(int len)
Definition:
fftcorr.cpp:47
fftcorr::inptrB
int inptrB
Definition:
fftcorr.h:53
fftcorr::run
int run(const cmplx &inA, const cmplx *inB, cmplx **out)
if inB = 0 then run auto-correlation
Definition:
fftcorr.cpp:62
fftcorr::dataB
cmplx * dataB
Definition:
fftcorr.h:49
fftcorr::outptr
int outptr
Definition:
fftcorr.h:54
Generated on Fri Aug 2 2019 17:56:33 for SDRAngel by
1.8.13