include iostream include cmath using namespace std const int sizeVec 5

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <cmath>
using namespace std;
const int sizeVec = 512;
const double PI = 4.0*atan(1.0);
double dft(int numSteps, int currentFreq);
double idft(int numSteps, int currentTime, double freqFunctionValue);
double timeFunction(double currentTime);
int main (int argc, char * const argv[]) {
bool goodToGo = true;
int loopMe = 0;
std::cout << "Hello, World!\n";
double freqVect[sizeVec];
double timeVect[sizeVec];
for(int m = 0; m < sizeVec; m++){
freqVect[m] = dft(sizeVec, m);
}
for(int n = 0; n < sizeVec; n++){
timeVect[n] = idft(sizeVec,n,freqVect[n])/(double)sizeVec;
}
while(goodToGo){
if(sizeVec == loopMe-1){
cout << "You did it!\n";
break;
}
if(1 < (abs(freqVect[loopMe] - timeVect[loopMe]))) goodToGo = false;
loopMe++;
cout << freqVect[loopMe] << " , " << timeVect[loopMe] << endl;
}
return 0;
}
double dft(int numSteps, int currentFreq){
double deltaT = 10/(double)numSteps;
double realPart = 0.0;
double imaginPart = 0.0;
for(int n = 0; n < numSteps; n++){
realPart += cos((-1*2*PI*currentFreq*n)/(double)numSteps)*timeFunction(deltaT*n);
// cout << realPart << ", ";
imaginPart += -1*sin((-1*2*PI*currentFreq*n)/(double)numSteps)*timeFunction(deltaT*n);
// cout << imaginPart << endl;
}
return (sqrt(pow(realPart,2)+pow(imaginPart,2)));
}
double idft(int numSteps, int currentTime, double freqFunctionValue){
double realPart = 0.0;
double imaginPart = 0.0;
for(int m = 0; m < numSteps; m++){
realPart += cos((2*PI*currentTime*m)/(double)numSteps)*freqFunctionValue;
imaginPart += -1*sin((2*PI*currentTime*m)/(double)numSteps)*freqFunctionValue;
}
return (sqrt(pow(realPart,2)+pow(imaginPart,2)));
}
double timeFunction(double currentTime){
return(exp(-1*pow(currentTime,2)/5)*sin(40*currentTime));
}