forked from AMSC-24-25/amsc-24-25-classroom-20-fft-FFT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
space-domain-signal-generator.hpp
50 lines (46 loc) · 2.17 KB
/
space-domain-signal-generator.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
48
49
50
#ifndef SPACE_DOMAIN_SIGNAL_GENERATOR_HPP
#define SPACE_DOMAIN_SIGNAL_GENERATOR_HPP
#include <complex>
#include <random>
#include "abstract-signal-generator.hpp"
class SpaceDomainSignalGenerator final : public AbstractSignalGenerator {
public:
explicit SpaceDomainSignalGenerator(const std::optional<int> seed = std::nullopt) : AbstractSignalGenerator(seed) {}
/**
* Generate a random (thanks to noise) one-dimensional signal in the space domain.
*
* Let the spatial frequency be k = frequency.
*
* Let the unique spatial coordinate be x (since it's 1D).
*
* Let the phase shift be phi.
*
* The signal is generated using the formula:
* @code
* signal(x) = (cos(2 * M_PI * k * x + phi) + noise) + j * (sin(2 * M_PI * k * x + phi) + noise)
* @endcode
* Where j is the imaginary unit.
*
* Using the parameters name of the function, the formula becomes:
* @code
* signal(x) = (cos(2 * M_PI * frequency * x + phase) + noise) + j * (sin(2 * M_PI * frequency * x + phase) + noise)
* @endcode
*
* In the mathematical literature, the formula is often written with its well-known form (Euler's formula):
* @code
* signal(x) = exp(j * (2 * M_PI * k * x + phi))
* @endcode
*
* A random noise is added to each formula to distort the signal.
*
* @param length The length of the signal. Specifies the number of points in the space domain.
* @param frequency Represents the spatial frequency, which determines how many cycles occur per unit distance.
* By "unit distance" we mean the distance between two consecutive samples in the spatial grid.
* It can be meters, millimeters, or any other spatial unit.
* @param phase The phase (shift) of the signal, which moves the waveform along the space axis (x since it's 1D).
* @param noise The range of the random noise added to each sample of the signal.
* @return The generated signal.
*/
std::vector<std::complex<double>> generate1DSignal(int length, double frequency, double phase, double noise) override;
};
#endif //SPACE_DOMAIN_SIGNAL_GENERATOR_HPP