Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <complex>
- #include <algorithm>
- #include <corecrt_math_defines.h>
- #include <string>
- #define _USE_MATH_DEFINES
- using namespace std;
- void FFT(vector < complex < double>>& a)
- {
- int n = a.size();
- if (n == 1) return;
- vector <complex<double>> a0(n / 2), a1(n / 2);
- for (int i = 0, j = 0; i < n; i += 2, j++)
- {
- a0[j] = a[i];
- a1[j] = a[i + 1];
- }
- FFT(a0);
- FFT(a1);
- double angle = 2 * M_PI / n;
- complex<double> tmp(1), temp(cos(angle), sin(angle));
- for (int i = 0; i < n / 2; i++)
- {
- a[i] = a0[i] + tmp * a1[i];
- a[i + n / 2] = a0[i] - tmp * a1[i];
- tmp *= temp;
- }
- }
- template <typename T>
- void write_vector(const vector<T>& V)
- {
- cout << "The numbers in the vector are: " << endl;
- for (int i = 0; i < V.size(); i++)
- cout << V[i] << " ";
- }
- int main()
- {
- int n;
- setlocale(LC_ALL, "Russian");
- cout << "Введите 2^k элементов" << endl;
- cout << "Введите значения в векторе.Чтобы закончить ввод, введите q";
- vector<complex<double>> v;
- int input;
- vector<int> V;
- while (cin >> input)
- {
- v.push_back(input);
- }
- cout << endl;
- cin.clear();
- FFT(v);
- cout << "Вектор после выполнения Преобразования Фурье:" << endl;
- for (int i = 0; i < v.size(); i++)
- {
- char znak = 0;
- if (v[i].imag() > 0) znak = '+';
- else znak = ' ';
- cout << v[i].real();
- if (v[i].imag() > 0) cout << '+' << v[i].imag() <<'i'<< endl;
- if (v[i].imag() < 0) cout << v[i].imag() <<'i'<< endl;
- else cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement