#include #include #include "Function.h" #include const double pi = acos(-1); //From numerical recipies void four11( vector& data, const int isign) { //vector > ret(vals.size()); //#include //#include "nr.h" //using namespace std; //void NR: :four1(Vec_io_dp &data, const int isign) // Replaces data [0. .2*nn-1] by its discrete Fourier transform, if isign is input as 1; or replaces // data [0. .2*nn-1] by nn times its inverse discrete Fourier transform, if isign is input as -1. // data is a complex array of length nn stored as a real array of length 2*nn. nn MUST be an // integer power of 2 (this is not checked for!) { int n , mmax, m, j, istep, i; double wtemp, wr, wpr, wpi, wi, theta, tempr, tempi; int nn=data .size( )/2; n=nn << 1; j=1; for (i=1; ii) { swap (data [j-1], data [i-1]); swap (data [j], data [i]) ; } m=nn; while (m>=2 && j>m) { j-=m; m>>=1; } j+=m; } mmax=2; while (n>mmax) { istep=mmax << 1; theta=isign*(6.28318530717959/mmax); wtemp=sin (0.5*theta); wpr = -2.0*wtemp*wtemp; wpi = sin(theta); wr=1.0; wi=0.0; for (m=1; m& vals, double secs, double sams) { double t; int i; vals.resize(secs*sams*2); cout << "# The sampled values are\n"; cout << "# Time \t f(t)\n"; for (t=0, i=0;t vals; //Problem 6.13 do { cout.precision(14); cout.width(14); cout << "\n# Welcome to the Fast Fourier Transform Program " << endl; cout << "# We will first examine the function :" << endl; cout << "# f(t) = cos( 6 * pi * t )" << endl; cout << "# How many seconds would you like to sample this function for (0 to quit)? "; cin >> secs; cout << "# How many samples would you like to take per second? "; cin >> sams; doFFT(f, vals, secs, sams); } while (secs); // Problem 6.15 secs = 1; Function& cos3t = cosF(self*3); do { cout << "\n# Please enter the number of seconds to sample cos3t (or 0 to quit): "; cin >> secs; doFFT(cos3t, vals, secs, 1); } while (secs); }