यह फ़ाइल ठीक तरह से काम करती है: बस अपने कंप्यूटर में कॉपी और पेस्ट करें। वेब पर सर्फिंग मुझे विकिपीडिया पेज here पर यह आसान कार्यान्वयन मिला है। पृष्ठ इतालवी में है, इसलिए मैंने कुछ अनुवादों के साथ कोड फिर से लिखा। Here लगभग समान जानकारी हैं लेकिन अंग्रेजी में। का आनंद लें!
#include <iostream>
#include <complex>
#define MAX 200
using namespace std;
#define M_PI 3.1415926535897932384
int log2(int N) /*function to calculate the log2(.) of int numbers*/
{
int k = N, i = 0;
while(k) {
k >>= 1;
i++;
}
return i - 1;
}
int check(int n) //checking if the number of element is a power of 2
{
return n > 0 && (n & (n - 1)) == 0;
}
int reverse(int N, int n) //calculating revers number
{
int j, p = 0;
for(j = 1; j <= log2(N); j++) {
if(n & (1 << (log2(N) - j)))
p |= 1 << (j - 1);
}
return p;
}
void ordina(complex<double>* f1, int N) //using the reverse order in the array
{
complex<double> f2[MAX];
for(int i = 0; i < N; i++)
f2[i] = f1[reverse(N, i)];
for(int j = 0; j < N; j++)
f1[j] = f2[j];
}
void transform(complex<double>* f, int N) //
{
ordina(f, N); //first: reverse order
complex<double> *W;
W = (complex<double> *)malloc(N/2 * sizeof(complex<double>));
W[1] = polar(1., -2. * M_PI/N);
W[0] = 1;
for(int i = 2; i < N/2; i++)
W[i] = pow(W[1], i);
int n = 1;
int a = N/2;
for(int j = 0; j < log2(N); j++) {
for(int i = 0; i < N; i++) {
if(!(i & n)) {
complex<double> temp = f[i];
complex<double> Temp = W[(i * a) % (n * a)] * f[i + n];
f[i] = temp + Temp;
f[i + n] = temp - Temp;
}
}
n *= 2;
a = a/2;
}
}
void FFT(complex<double>* f, int N, double d)
{
transform(f, N);
for(int i = 0; i < N; i++)
f[i] *= d; //multiplying by step
}
int main()
{
int n;
do {
cout << "specify array dimension (MUST be power of 2)" << endl;
cin >> n;
} while(!check(n));
double d;
cout << "specify sampling step" << endl; //just write 1 in order to have the same results of matlab fft(.)
cin >> d;
complex<double> vec[MAX];
cout << "specify the array" << endl;
for(int i = 0; i < n; i++) {
cout << "specify element number: " << i << endl;
cin >> vec[i];
}
FFT(vec, n, d);
cout << "...printing the FFT of the array specified" << endl;
for(int j = 0; j < n; j++)
cout << vec[j] << endl;
return 0;
}
कोशिश [GitHub पर 'fft' की खोज करने] (https://github.com/search?langOverride=c&q=fft&repo=&start_value=1&type=Repositories)। लेकिन एफएफटीडब्ल्यू के बारे में क्या उपयोग करना आसान नहीं है? क्या आपका मतलब स्रोत को समझना आसान है? – Rup
अपना खुद का लिखें। यह एक अच्छा अभ्यास होगा। इंटरनेट डीएफटी और एफएफटी की गणना करने के तरीके के बारे में स्पष्टीकरण से भरा है। उसका उपयोग करें। –
एफएफटी दिनचर्या [यहां] (http://www.fit.vutbr.cz/research/prod/?id=510) कोड की सौ से कम पंक्तियां हैं। लाइब्रेरी समय में (डीआईटी) और आवृत्ति में डीकिमेशन (डीआईएफ) का उपयोग करके आगे और व्यस्त तेज़ फूरियर ट्रांसफॉर्म (एफएफटी) एल्गोरिदम लागू करता है। – DaBler