// ftdemo - Discrete Fourier transform demonstration program #include "NumMeth.h" void fft( Matrix& RealA, Matrix& ImagA); void main() { //* Initialize the sine wave time series to be transformed. cout << "Enter the number of points: "; int N; cin >> N; cout << "Enter frequency of the sine wave: "; double freq; cin >> freq; cout << "Enter phase of the sine wave: "; double phase; cin >> phase; double tau = 1; // Time increment const double pi = 3.141592654; Matrix t(N), y(N), f(N); int i,j,k; for( i=1; i<=N; i++ ) { t(i) = (i-1)*tau; // t = [0, tau, 2*tau, ... ] y(i) = sin(2*pi*t(i)*freq + phase); // Sine wave time series f(i) = (i-1)/(N*tau); // f = [0, 1/(N*tau), ... ] } //* Compute the transform using desired method: direct summation // or fast Fourier transform (FFT) algorithm. Matrix ytReal(N), ytImag(N); cout << "Compute transform by, 1) Direct summation; 2) FFT: "; int method; cin >> method; if( method == 1 ) { // Direct summation double twoPiN = -2*pi/N; for( k=0; k