2019-11-26 12:24:33 +00:00
|
|
|
#include <math.hpp>
|
2019-11-26 09:56:37 +00:00
|
|
|
#include <cmath>
|
2019-11-26 17:01:16 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
void create_plot_file(std::string filename, const math::csignal& tfd) {
|
|
|
|
std::ofstream data_file(filename + ".data");
|
|
|
|
for (int i=0; i<tfd.size(); ++i) {
|
|
|
|
data_file << tfd[i].real()
|
|
|
|
<< " "
|
|
|
|
<< tfd[i].imag()
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
data_file.close();
|
|
|
|
}
|
2019-11-26 09:56:37 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
2019-11-26 12:24:33 +00:00
|
|
|
math::csignal s;
|
2019-11-26 17:01:16 +00:00
|
|
|
double fe = 6000;
|
|
|
|
double f0 = 400;
|
|
|
|
int n = 30;
|
|
|
|
if (argc > 1) {
|
|
|
|
n = atoi(argv[1]);
|
|
|
|
}
|
2019-11-26 09:56:37 +00:00
|
|
|
|
2019-11-26 12:24:33 +00:00
|
|
|
for (int i=0; i<100; ++i) {
|
2019-11-26 17:01:16 +00:00
|
|
|
s.push_back(math::complex(std::sin(2*math::pi()*f0*float(i)/fe), 0));
|
2019-11-26 12:24:33 +00:00
|
|
|
}
|
2019-11-26 09:56:37 +00:00
|
|
|
|
2019-11-28 15:08:21 +00:00
|
|
|
std::cout << math::mean(s) << std::endl;
|
|
|
|
|
2019-11-26 17:01:16 +00:00
|
|
|
math::csignal tfd;
|
|
|
|
clock_t begin = std::clock();
|
|
|
|
|
|
|
|
for (int i=0; i<n; ++i) {
|
|
|
|
tfd = math::fft(s, 2000);
|
|
|
|
}
|
|
|
|
|
|
|
|
clock_t end = clock();
|
|
|
|
std::cout << "Time to compute " << n << " fft: "<< double(end-begin) / CLOCKS_PER_SEC << std::endl;
|
|
|
|
std::cout << "Average time: " << double(end-begin) / CLOCKS_PER_SEC / n << std::endl;
|
|
|
|
|
|
|
|
math::csignal mod;
|
|
|
|
for (int i=0; i<tfd.size(); ++i) {
|
|
|
|
double R = tfd[i].real();
|
|
|
|
double I = tfd[i].imag();
|
|
|
|
double a = std::sqrt(R*R + I*I);
|
|
|
|
mod.push_back(math::complex(float(i)/tfd.size()*fe, a));
|
|
|
|
}
|
|
|
|
create_plot_file("graph", mod);
|
2019-11-26 12:24:33 +00:00
|
|
|
return 0;
|
2019-11-26 09:56:37 +00:00
|
|
|
}
|