forked from AMSC-24-25/20-fft-20-fft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space-domain-signal-generator.cpp
30 lines (28 loc) · 1.21 KB
/
space-domain-signal-generator.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
#include "signal-generator/space-domain-signal-generator.hpp"
#include <iostream>
std::vector<std::complex<double> > SpaceDomainSignalGenerator::generate1DSignal(
const int length, const double frequency, const double phase, const double noise
) {
// init
std::vector<std::complex<double>> signal;
// reserve the space for the signal
try {
signal.reserve(length);
} catch (std::length_error &e) {
std::cerr << "Error: the length of the signal cannot be grater than " << signal.max_size()
<< ". Reason: " << e.what() << std::endl;
}
// there is memory space for the signal, so generate it
// initialize the Gaussian distribution for the noise
std::normal_distribution<> gaussian(0, noise);
// angular spatial frequency or wave number
const double angular_spatial_frequency = 2 * M_PI * frequency;
// generate the signal 1D, so we have only one spatial coordinate called x for convenience
for (int x = 0; x < length; ++x) {
signal.emplace_back(
std::cos(angular_spatial_frequency * x + phase) + gaussian(_engine),
std::sin(angular_spatial_frequency * x + phase) + gaussian(_engine)
);
}
return signal;
}