Advertisement
Soverein

Untitled

Nov 11th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include<chrono>
  6. using namespace std;
  7. #define PI 3.14159265
  8. class DFT_Coeff {
  9. public:
  10.     double real, img;
  11.     DFT_Coeff() {
  12.         real = 0.0;
  13.         img = 0.0;
  14.     }
  15. };
  16. int main(int argc, char** argv)
  17. {
  18.     auto begin = std::chrono::steady_clock::now();
  19.     const int M = 10;
  20.     cout << "Enter the coefficient of simple linear function:\n";
  21.     cout << "ax + by = c\n";
  22.     double a, b, c;
  23.     cin >> a >> b >> c;
  24.     double function[M];
  25.     for (int i = 0; i < M; i++) {
  26.         function[i] = (((a * (double)i) + (b * (double)i)) - c);
  27.         //System.out.print( " "+function[i] + " ");
  28.     }
  29.     cout << "Enter the max K value: ";
  30.     const int k=10;
  31.     double cosine[M];
  32.     double sine[M];
  33.     for (int i = 0; i < M; i++) {
  34.         cosine[i] = cos((2 * i * k * PI) / M);
  35.         sine[i] = sin((2 * i * k * PI) / M);
  36.     }
  37.     DFT_Coeff dft_value[k];
  38.     cout << "The coefficients are: "<<endl;
  39.     for (int j = 0; j < k; j++) {
  40.         for (int i = 0; i < M; i++) {
  41.             dft_value[j].real += function[i] * cosine[i];
  42.             dft_value[j].img += function[i] * sine[i];
  43.         }
  44.         cout << "(" << dft_value[j].real << ") - " << "(" << dft_value[j].img << " i)\n";
  45.     }
  46.     getchar();
  47.     auto end = std::chrono::steady_clock::now();
  48.  
  49.     auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin);
  50.     std::cout << "The time: " << elapsed_ms.count() << " ms\n";
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement