डिस्क्रीट फूरियर ट्रांसफॉर्म (DFT) में, एक परिमित सूची को एक फंक्शन के समान रूप से स्पेस्ड सैंपल्स की सूची को कॉम्प्लेक्स साइनसॉइड्स के परिमित संयोजन के गुणांकों की सूची में बदला जाता है। वे उनकी फ्रीक्वेंसी द्वारा क्रमबद्ध होते हैं, जिनमें वे समान सैंपल वैल्यू होती हैं, सैंपल्ड फंक्शन को उसके मूल डोमेन (अक्सर समय या एक रेखा के साथ स्थिति) से फ्रीक्वेंसी डोमेन में बदलने के लिए।
एल्गोरिदम
Begin
तीन वेरिएबल घोषित करें जो रैखिक समीकरण के गुणांक और अधिकतम मान हैं
वेरिएबल पढ़ें
दो वेरिएबल real, img के साथ एक क्लास परिभाषित करें
एक कंस्ट्रक्टर बनाएं और real, img को शून्य पर सेट करें
एक वेरिएबल M लें और इसे किसी इंटीजर से इनिशियलाइज़ करें
function[M] बनाएं
i=0 से M तक करें
function[i] = (((a * (double) i) + (b * (double) i)) - c)
sine[M] फंक्शन घोषित करें
cosine[M] फंक्शन घोषित करें
i = 0 से M तक करें
cosine[i] = cos((2 * i * k * PI) / M)
sine[i] = sin((2 * i * k * PI) / M)
i = 0 से M तक करें
dft_value.real += function[i] * cosine[i]
dft_value.img += function[i] * sine[i]
वैल्यू प्रिंट करें
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)