-
Notifications
You must be signed in to change notification settings - Fork 16
/
waveform.cpp
79 lines (62 loc) · 2.51 KB
/
waveform.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
USRP_Software_defined_radar is a software for real time sampling, processing, display and storing
Copyright (C) 2018 Jonas Myhre Christiansen <[email protected]>
This file is part of USRP_Software_defined_radar.
USRP_Software_defined_radar is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
USRP_Software_defined_radar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with USRP_Software_defined_radar. If not, see <https://www.gnu.org/licenses/>.
*/
#include "waveform.h"
Waveform::Waveform()
{
Waveform_type = WAVEFORM_TYPE_LFM;
}
long int Waveform::generateWaveform(std::vector<std::complex<PRECISION>> *wfVector) {
long int Nwaveform = (long int) (tau * fs);
long int k;
std::vector<double> phi(Nwaveform,0);
std::vector<PRECISION> *from_file = NULL;
if (wfVector->size()<Nwaveform) {
return WAVEFORM_ERROR_VECTOR_TOO_SHORT;
}
if(Waveform_type==WAVEFORM_TYPE_FROM_FILE) {
std::ifstream in(fileName, std::ios::binary);
in.seekg (0, in.end);
long int length = in.tellg();
in.seekg (0, in.beg);
from_file = new std::vector<PRECISION>(length/4);
in.read((char*) &(from_file->front()), length);
in.close();
Nwaveform = (size_t) length/8;
}
switch(Waveform_type) {
// Quadratic phase evolution (linear freq)
case WAVEFORM_TYPE_LFM:
for(k=1;k<Nwaveform;k++) {
phi[k] = phi[k-1] + (2*M_PI)*((k-Nwaveform/2)*Bandwidth/Nwaveform)/fs;
}
break;
// Const phase 0, zero frequency pules
case WAVEFORM_TYPE_RECT:
break;
}
for(k=0; k<Nwaveform; k++) {
// If from file, storing binary waveform in wfVector
if(Waveform_type==WAVEFORM_TYPE_FROM_FILE) {
(*wfVector)[k] = std::complex<PRECISION>((*from_file)[2*k], (*from_file)[2*k+1]);
} else {
(*wfVector)[k] = std::exp(std::complex<PRECISION>(0,phi[k]));
}
}
if(Waveform_type==WAVEFORM_TYPE_FROM_FILE && from_file!=NULL) {
delete from_file;
}
return Nwaveform;
}