DSPRelated.com
Forums

FFTW Library - am i using it right??

Started by katz April 3, 2005
hello,

i would like to know if i'm doing this right. my program creates a vector
of vectors which it then FFTs using the FFTW library. its written in C++.
my full code is shown below. if this is right, the next step would be to
correlate this vector with another. 

anyway, heres my code:

...
#include "fftw3.h"
using namespace std;

typedef vector<int> convert;
typedef vector<int> row;

int main()
{
    ifstream inFile;
    inFile.open("data2.txt");
    
    if (inFile.fail())
    {
         cout <<"\nThe file was not successfully opened" << endl;
         exit(1);
    }

    //vector of vectors which holds each line in the data file as a
vector
    
    string one_line;
    double probability;
    
    while (getline(inFile, one_line, '\n'))
    {      
           vector<convert> BinaryVector; //vector which holds data file  
                                         //in binary format
           vector<int> Element;
               
           cout << "Line: " << one_line << endl;
           vector<double> Line; // holds a single line of the data file
           istringstream lineStream( one_line );
        
           while( lineStream >> probability )
           {
               Line.push_back( probability ); //stores prob in Line
vector.
               
               int data;
               if (probability == 0)
               { data = 0; }
               
               else
               { data = 1; }
               
               Element.push_back( data );
           }
         
           SourceData.push_back( Line );
           BinaryVector.push_back( Element );
           
           double *in, *out;
           fftw_plan p; 
           int nx = Element.size();
           int i;

           in = (double*)fftw_malloc(sizeof(double) * nx );
           out = (double*)fftw_malloc(sizeof(double) * nx);
    
           p = fftw_plan_r2r(nx, in, out, const fftw_r2r_kind FFTW_R2HC,
FFTW_ESTIMATE, FFTW_FORWARD);
           
           //fill input array
           int *array = new int[Element.size()]; 
           for(int i = 0; i < Element.size(); i++) 
           {    array[i] = Element[i]; }
    
           // execute plan
           fftw_execute(p);
           
           // destroy plan
           fftw_destroy_plan(p);
           fftw_free(in); 
           fftw_free(out);        
   }
     
    system("PAUSE");
    return 0;

}

oh yeah...i also keep getting the following error message which i'm not
sure how to fix:
"expected primary expression before const" for line

p = fftw_plan_r2r(nx, in, out, const fftw_r2r_kind FFTW_R2HC,
FFTW_ESTIMATE, FFTW_FORWARD);

any help would be greatly appreciated. 

thanx in advance,
katz
		
This message was sent using the Comp.DSP web interface on
www.DSPRelated.com
katz wrote:

> ... > #include "fftw3.h" > using namespace std; > > typedef vector<int> convert; > typedef vector<int> row;
Why bother with two different names for the same thing?
> int main() > { > ifstream inFile; > inFile.open("data2.txt"); > > if (inFile.fail()) > { > cout <<"\nThe file was not successfully opened" << endl; > exit(1); > } > > //vector of vectors which holds each line in the data file as a > vector > > string one_line; > double probability; > > while (getline(inFile, one_line, '\n'))
Why not inFile.getline(...) ?
> { > vector<convert> BinaryVector; //vector which holds data
file
> //in binary format
So BinaryVector is a vector of vector of int?
> vector<int> Element;
Why not use the typedef's you made above?
> cout << "Line: " << one_line << endl; > vector<double> Line; // holds a single line of the data
file What's the difference between "one_line" and "Line" then?
> istringstream lineStream( one_line ); > > while( lineStream >> probability ) > { > Line.push_back( probability ); //stores prob in Line > vector. > > int data; > if (probability == 0) > { data = 0; } > > else > { data = 1; } > > Element.push_back( data ); > } > > SourceData.push_back( Line );
Why have you just push_back-ed a variable that you've done nothing with?
> BinaryVector.push_back( Element );
Element is just ones and zeros?
> double *in, *out; > fftw_plan p; > int nx = Element.size(); > int i; > > in = (double*)fftw_malloc(sizeof(double) * nx ); > out = (double*)fftw_malloc(sizeof(double) * nx); > > p = fftw_plan_r2r(nx, in, out, const fftw_r2r_kind
FFTW_R2HC,
> FFTW_ESTIMATE, FFTW_FORWARD);
Is FFTW_R2HC of the correct type?
> //fill input array > int *array = new int[Element.size()]; > for(int i = 0; i < Element.size(); i++) > { array[i] = Element[i]; }
What does that do?
> // execute plan > fftw_execute(p);
Don't you have to load data into "in"?? That seems odd. How does fftw_execute know that array contains the data?
> // destroy plan > fftw_destroy_plan(p); > fftw_free(in); > fftw_free(out); > } > > system("PAUSE"); > return 0; > > } > > oh yeah...i also keep getting the following error message which > i'm not sure how to fix: > "expected primary expression before const" for line > > p = fftw_plan_r2r(nx, in, out, const fftw_r2r_kind FFTW_R2HC, > FFTW_ESTIMATE, FFTW_FORWARD); > > any help would be greatly appreciated. > > thanx in advance, > katz > > This message was sent using the Comp.DSP web interface on > www.DSPRelated.com
This message was sent using the comp.dsp web interface on groups-beta.google.comn.
katz wrote:
>
<snip>
> oh yeah...i also keep getting the following error message which i'm not > sure how to fix: > "expected primary expression before const" for line > > p = fftw_plan_r2r(nx, in, out, const fftw_r2r_kind FFTW_R2HC,
I think you need to remove the "const fftw_r2r_kind" from the line above.
> This message was sent using the Comp.DSP web interface on > www.DSPRelated.com
You should also learn how to use Usenet the way it is intended. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ "Using Java as a general purpose application development language is like going big game hunting armed with Nerf weapons." -- Author Unknown