-
Notifications
You must be signed in to change notification settings - Fork 48
/
ChirpGenerator.hpp
47 lines (45 loc) · 1.39 KB
/
ChirpGenerator.hpp
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
47
// Copyright (c) 2016-2016 Lime Microsystems
// SPDX-License-Identifier: BSL-1.0
#pragma once
#include <Pothos/Config.hpp>
#include <complex>
#include <cmath>
/*!
* Generate a chirp
* \param [out] samps pointer to the output samples
* \param N samples per chirp sans the oversampling
* \param ovs the oversampling size
* \param NN the number of samples to generate
* \param f0 the phase offset/transmit symbol
* \param down true for downchirp, false for up
* \param ampl the chrip amplitude
* \param [inout] phaseAccum running phase accumulator value
* \return the number of samples generated
*/
template <typename Type>
int genChirp(std::complex<Type> *samps, int N, int ovs, int NN, Type f0, bool down, const Type ampl, Type &phaseAccum)
{
const Type fMin = -M_PI / ovs;
const Type fMax = M_PI / ovs;
const Type fStep = (2 * M_PI) / (N * ovs * ovs);
float f = fMin + f0;
int i;
if (down) {
for (i = 0; i < NN; i++) {
f += fStep;
if (f > fMax) f -= (fMax - fMin);
phaseAccum -= f;
samps[i] = std::polar(ampl, phaseAccum);
}
}
else {
for (i = 0; i < NN; i++) {
f += fStep;
if (f > fMax) f -= (fMax - fMin);
phaseAccum += f;
samps[i] = std::polar(ampl, phaseAccum);
}
}
phaseAccum -= floor(phaseAccum / (2 * M_PI)) * 2 * M_PI;
return i;
}