কম্পিউটার

সরাসরি DFT সহগ গণনা করার জন্য C++ প্রোগ্রাম


বিচ্ছিন্ন ফুরিয়ার ট্রান্সফর্মে (DFT), একটি সসীম তালিকা একটি ফাংশনের সমান ব্যবধানের নমুনাগুলিকে জটিল সাইনোসয়েডগুলির একটি সীমাবদ্ধ সংমিশ্রণের সহগগুলির তালিকায় রূপান্তরিত করা হয়। তারা তাদের ফ্রিকোয়েন্সি অনুসারে অর্ডার করে, যার একই নমুনা মান রয়েছে, নমুনাকৃত ফাংশনকে তার আসল ডোমেন (প্রায়শই সময় বা একটি লাইন বরাবর অবস্থান) থেকে ফ্রিকোয়েন্সি ডোমেনে রূপান্তর করতে।

অ্যালগরিদম

Begin
   Declare three variables which are the coefficient of linear equation and max value
   Read the variables
   Define a class with two variables real, img
   Create a constructor and set real, img to zero
   Take a variable M and initialize it to some integer
   Create function[M]
   For i=0 to M do
      function[i] = (((a * (double) i) + (b * (double) i)) - c)
   Declare function sine[M]
   Declare function cosine[M]
   for i = 0 to M do
      cosine[i] = cos((2 * i * k * PI) / M)
      sine[i] = sin((2 * i * k * PI) / M)
   for i = 0 to M do
      dft_value.real += function[i] * cosine[i]
      dft_value.img += function[i] * sine[i]
   Print the value
End

উদাহরণ কোড

#include<iostream>
#include<math.h>
using namespace std;
#define PI 3.14159265
class DFT_Coeff {
   public:
   double real, img;
   DFT_Coeff() {
      real = 0.0;
      img = 0.0;
   }
};
int main(int argc, char **argv) {
   int M = 10;
   cout << "Enter the coeff of simple linear function:\n";
   cout << "ax + by = c\n";
   double a, b, c;
   cin >> a >> b >> c;
   double function[M];
   for (int i = 0; i < M; i++) {
      function[i] = (((a * (double) i) + (b * (double) i)) - c);
   }
   cout << "Enter the max K value: ";
   int k;
   cin >> k;
   double cosine[M];
   double sine[M];
   for (int i = 0; i < M; i++) {
      cosine[i] = cos((2 * i * k * PI) / M);
      sine[i] = sin((2 * i * k * PI) / M);
   }
   DFT_Coeff dft_value;
   cout << "The coeffs are: ";
   for (int i = 0; i < M; i++) {
      dft_value.real += function[i] * cosine[i];
      dft_value.img += function[i] * sine[i];
   }
   cout << "(" << dft_value.real << ") - " << "(" << dft_value.img << " i)";
}

আউটপুট

Enter the coeff of simple linear function:
ax + by = c
4 6 7
Enter the max K value:
4
The coeffs are: (-50) - (-16.246 i)

  1. C++ প্রোগ্রামে বাইনারি অনুসন্ধান?

  2. LCM খুঁজে পেতে C++ প্রোগ্রাম

  3. GCD খুঁজে পেতে C++ প্রোগ্রাম

  4. C++ হ্যালো, বিশ্ব! কার্যক্রম