realFFTExample.cc

This is an example of how to use the class. It transforms a sine tone stored in the .dat file and saves the in, out, and power_spectrum results of using the class

00001 /* Copyright 2001,2002 Matt Flax <flatmax@ieee.org>
00002    This file is part of the MFFM FFTw Wrapper library.
00003 
00004    MFFM MFFM FFTw Wrapper library is free software; you can 
00005    redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009    
00010    MFFM FFTw Wrapper library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014    
00015    You have received a copy of the GNU General Public License
00016    along with the MFFM FFTw Wrapper library
00017 */
00018 #include <fstream>
00019 #include <iomanip>
00020 
00021 #include <mffm/realFFT.H>
00022 
00023 #define INPUTFILE "sine.1000Hz.dat"
00024 #define OUTPUTFILE "powerSpectrum.txt"
00025 #define OUTPUTFILE1 "in.txt"
00026 #define OUTPUTFILE2 "out.txt"
00027 
00028 int main (void){
00029   ifstream input(INPUTFILE);
00030   ofstream output(OUTPUTFILE);
00031   ofstream output1(OUTPUTFILE1);
00032   ofstream output2(OUTPUTFILE2);
00033   int count=0;
00034   double var;
00035   // Get the file size and check file exists ....
00036   if (!input){
00037     cout <<"input not opened !"<<endl;
00038     exit(-1);
00039   }
00040   while (input >> var)
00041     count++;
00042   //input.close();
00043   
00044   cout<<count<<" variables in file "<<INPUTFILE<<endl;
00045 
00046   //input.open(INPUTFILE);
00047   input.clear();
00048   input.seekg(0);
00049  
00050   realFFTData fftData(count);
00051   realFFT rfft(&fftData);
00052 
00053   // read data into data and rdata :
00054   for (int i=0; i<count; i++)
00055     input >> fftData.in[i];
00056   input.close();
00057 
00058   // forward transform :
00059   rfft.fwdTransform();
00060 
00061   // Find the power spectrum ...
00062   fftData.compPowerSpec();
00063   /*
00064   // inverse transform to check what happens (have to rescale too): 
00065   rfft.invTransform();
00066   */
00067   // output to file :
00068   for (int i=0; i<(count+1)/2; i++){
00069     output << fftData.power_spectrum[i]<<'\n';
00070   }
00071   //  cout <<(count+1)/2<<endl;
00072   output.close();
00073 
00074   for (int i=0; i<count; i++){
00075     output1 << fftData.in[i]<<'\n';
00076     output2 << fftData.out[i]<<'\n';
00077   }
00078   output1.close();
00079   output2.close();
00080   return 0;
00081 }

Generated on Thu Oct 27 02:45:42 2005 for MFFM FFTw Wrapper by  doxygen 1.4.5