4 changed files with 51 additions and 107 deletions
@ -1,51 +1,13 @@ |
|||
#include <fftw3.h> |
|||
#include <math.hpp> |
|||
#include <cmath> |
|||
#include <libplotcpp/plotcpp.hpp> |
|||
|
|||
double pi() { |
|||
return 3.1415; |
|||
} |
|||
|
|||
std::vector<double> tfd2vect(fftw_complex* tfd, int N) { |
|||
std::vector<double> res; |
|||
auto it = tfd; |
|||
for (int i = 0; i != N; ++i) { |
|||
fftw_complex c = {*it[0], *it[1]}; |
|||
res.push_back(sqrt(c[0]*c[0] + c[1]*c[1])); |
|||
it++; |
|||
} |
|||
|
|||
return res; |
|||
} |
|||
|
|||
int main(int argc, char** argv) { |
|||
QApplication app(argc, argv); |
|||
fftw_complex *in, *out; |
|||
fftw_plan p; |
|||
|
|||
int N = 500; |
|||
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); |
|||
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N); |
|||
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_MEASURE); |
|||
|
|||
std::vector<double> xx; |
|||
for (int i = 0; i != N; ++i) { |
|||
xx.push_back(i); |
|||
} |
|||
|
|||
for (int i = 0; i != N; ++i) { |
|||
in[i][0] = sin(2*pi()*50*i/N); |
|||
} |
|||
|
|||
fftw_execute(p); /* repeat as needed */ |
|||
|
|||
std::vector<double> res = tfd2vect(out, N); |
|||
PlotCpp g; |
|||
g.plot(xx, res); |
|||
g.draw(); |
|||
math::csignal s; |
|||
|
|||
for (int i=0; i<100; ++i) { |
|||
s.push_back(std::sin(2*math::pi()*50*i/100)); |
|||
} |
|||
math::csignal tfd = math::fft(s); |
|||
|
|||
fftw_destroy_plan(p); |
|||
fftw_free(in); fftw_free(out); |
|||
return app.exec(); |
|||
return 0; |
|||
} |
|||
|
|||
@ -1,13 +0,0 @@ |
|||
#include <math.hpp> |
|||
#include <cmath> |
|||
|
|||
int main(int argc, char** argv) { |
|||
math::signal s; |
|||
|
|||
for (int i=0; i<100; ++i) { |
|||
s.push_back(std::sin(2*math::pi()*50*i/100)); |
|||
} |
|||
math::fft(s); |
|||
|
|||
return 0; |
|||
} |
|||
Loading…
Reference in new issue