Implémentation de la fft

This commit is contained in:
Guillaume Courrier 2019-11-26 13:50:55 +01:00
parent 5be8c8533a
commit 79e8e2cedd

View file

@ -33,18 +33,19 @@ namespace math {
return complex(res.real()/sig.size(), res.imag()/sig.size()); return complex(res.real()/sig.size(), res.imag()/sig.size());
}; };
//TODO: implémenter la fonction
csignal diff(const csignal& input, complex mean) { csignal diff(const csignal& input, complex mean) {
return csignal(); csignal res;
for (auto x: input) {
res.push_back(x - mean);
}
return res;
} }
//TODO implémenter la fft
csignal fft_rec(const csignal& input) { csignal fft_rec(const csignal& input) {
int size = input.size(); int size = input.size();
if (size == 1) { if (size == 1) {
//TODO: que faire dans ce cas ? return input;
return csignal();
} else { } else {
csignal odd; csignal odd;
csignal even; csignal even;
@ -90,7 +91,6 @@ namespace math {
int kmax = 2*cmax; int kmax = 2*cmax;
for (int m=0; m<tfd.size(); ++m) { for (int m=0; m<tfd.size(); ++m) {
//TODO: retrouver la formule
complex sum; complex sum;
for (int k=kmin; k<kmax; ++k) { for (int k=kmin; k<kmax; ++k) {
sum += tfd[k]*std::exp(complex(0, 2*pi()*k*m/tfd.size())); sum += tfd[k]*std::exp(complex(0, 2*pi()*k*m/tfd.size()));
@ -105,8 +105,7 @@ namespace math {
contour res; contour res;
csignal z = cont2sig(cont); csignal z = cont2sig(cont);
complex zm = mean(z); complex zm = mean(z);
//TODO: fft(diff(z, zm)); csignal tfd = fft(diff(z, zm));
csignal tfd = fft(z);
return coef2cont(tfd, zm, 0, cmax); return coef2cont(tfd, zm, 0, cmax);
}; };