DFT routine

R

Roberto Dias

I developed a DFT routine using a language named "ATP Model Language".
It is based on FORTRAN and specific to electromagnetic transients
simulations, a study field in electrical engineering. Few months ago,
I cought up on C++ readings and, nowadays, fell very bad to retarn to
"FORTRAN". My Discret Fourier Trasmoration Routine (DFT) is used to
filtering data from electrical system by digital relays. Could you
help me with some tips to develop a routine like this one using C++
OOP? Or maybe help me to translate a "function-oriented" (Fortran) in
C++?

Thanks,

Roberto Dias
 
J

Jeff Schwab

Roberto said:
I developed a DFT routine using a language named "ATP Model Language".
It is based on FORTRAN and specific to electromagnetic transients
simulations, a study field in electrical engineering. Few months ago,
I cought up on C++ readings and, nowadays, fell very bad to retarn to
"FORTRAN". My Discret Fourier Trasmoration Routine (DFT)

Ah, that's better. In my industry, DFT means "design for test."
is used to
filtering data from electrical system by digital relays. Could you
help me with some tips to develop a routine like this one using C++
OOP?

Like which one? The one you developed in Fortran? What specific
functionality do you want?
Or maybe help me to translate a "function-oriented" (Fortran) in
C++?

You can use a "function-oriented" approach in C++, too. You can use
classes if you feel it's appropriate, but you certainly don't have to do
so. In fact, you generally can call your Fortran routines directly from
C++ code. Here's an example of a math library including discrete
Fourier transforms that's callable from C, C++, and Fortran:

http://webdocs.caspur.it/ibm/web/pessl-2.2/pessl031.html#HDRXSOA

If you just want a DFT library written in C++, try Googling for a while.
 
T

Thomas Matthews

Roberto said:
I developed a DFT routine using a language named "ATP Model Language".
It is based on FORTRAN and specific to electromagnetic transients
simulations, a study field in electrical engineering. Few months ago,
I cought up on C++ readings and, nowadays, fell very bad to retarn to
"FORTRAN". My Discret Fourier Trasmoration Routine (DFT) is used to
filtering data from electrical system by digital relays. Could you
help me with some tips to develop a routine like this one using C++
OOP? Or maybe help me to translate a "function-oriented" (Fortran) in
C++?

Thanks,

Roberto Dias

There are several methods to go about your project:
1. Use somebody else's software.
2. Use existing libraries and just write "glue-ware".
3. Write your own from scratch.

The first two require the use of a web search engine,
which is off-topic to this newsgroup. For example,
one might use the keywords "Discrete Fourier Transformation
Filter C++ Library" (make sure the spelling is correct).
You could reorder the terms in order of importance:
"Fourier Transformation Descrete C++ Library".


Writing your own
----------------
From lurking in this newsgroup and after reading the
FAQ and Welcome.Txt, you know that the best method
is to start out small and work up.

We all know that a good starting point is with a simple
program:
#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;

int main(void)
{
cout << "It works!" << endl;
return EXIT_SUCCESS;
}


The Next Step: Input
---------------------
An FFT (Fast Fourier Transform) or a DFT requires data.
There are two routes here:
1. Place test data inside the program.
2. Input data from a file.
In the embedded systems arena, I would go with #1. Often
times, the platforms don't support files. However, in
this case we'll go with route 2.

So, add input capability to your main program. For simplicity,
just input the data and spit it back out.
#include <iostream>
#include <fstream>
#include <cstdlib>
using std::cerr;
using std::cout;
using std::endl;
using std::ifstream;

#define DATA_TYPE int // Change this to match your data type.

const char INPUT_FILENAME[] = "dft.data";

int main(void)
{
// Assume ASCII represented data i.e. "12" not 12.
ifstream inp(INPUT_FILENAME);

// Always check for errors after opening a file.
if (!inp)
{
cerr << "Error opening input file, "
<< INPUT_FILENAME
<< endl;
return EXIT_FAILURE;
}

DATA_TYPE value;

// Input one value and spit it out:
if (inp >> value)
{
cout << "Value read: " << value << endl;
}
else
{
cerr << "Error reading input data." << endl;
return EXIT_FAILURE;
}

// Read all the values and spit them out:
while (inp >> value)
{
cout << value << endl;
}

// A proper program closes the file before exiting.
inp.close();

return EXIT_SUCCESS;
}


Next: Adding Computation
-------------------------
After the above program works, we know that we can
input data properly, which is very important.

The next step is to perform the computation. But
this requires some planning or design. Here are
some routes:
1. DFT wants all data at once.
2. DFT can handle one value at a time.
For route #2, we just add a function call inside
the input loop. For route #1, we append each value
to a vector, then after all values are read in, we
pass the vector to the DFT:
#include <vector>
//...
using std::vector;

#define DFT_RESULT_TYPE int // or whatever your's is.

// Create a function declaration.
DFT_RESULT_TYPE My_Dft(vector<DATA_TYPE>& dft_values);

//...
int main(void)
{
vector<DATA_TYPE> dft_values;
DFT_RESULT_TYPE result;

//...
while (inp >> value)
{
dft_values.push_back(value);
}

// Process the data.
result = My_Dft(dft_values);

// Output the result
cout << "DFT result: " << result << endl;

// ...
return EXIT_SUCCESS;
}


DFT_RESULT_TYPE My_Dft(vector<DATA_TYPE>& dft_values)
{
cout << "Processing " << dft_values.size()
<< " values" << endl;
return 12; // Some test value.
}


After the above modifications have been made and tested,
you now can go on and add details to the DFT routine.
Follow this method of writing simple test programs,
getting them to work, then building up.

Search the Web for "Test Driven Development".

Hope that helps.




--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
R

Raghavendra Mahuli

why dont u use MATLAB.....U can use MATLAB's c++ interface to convert code
in MATLAB and get it in C++
 
R

Roberto Dias

Jeff Schwab said:
Ah, that's better. In my industry, DFT means "design for test."


Like which one? The one you developed in Fortran? What specific
functionality do you want?
When you use DFT filtering, you are interested in convert cosinoidal
measured values into phasor (Module, Angle) that belongs to the
frequency domain, I mean, handle complex values is essencial. Yes I
partialy-developed using FORTRAN, but I indentified that if a OOP
approach will be used, re-using advantage could compress my source
file.
You can use a "function-oriented" approach in C++, too. You can use
classes if you feel it's appropriate, but you certainly don't have to do
so. In fact, you generally can call your Fortran routines directly from
C++ code. Here's an example of a math library including discrete
Fourier transforms that's callable from C, C++, and Fortran:

http://webdocs.caspur.it/ibm/web/pessl-2.2/pessl031.html#HDRXSOA

If you just want a DFT library written in C++, try Googling for a while.
Thank you very much. I didn't realized this. Call FORTRAN like
subroutines... What good ideia.
 
J

Jeff Schwab

Roberto said:
When you use DFT filtering, you are interested in convert cosinoidal
Sinusoidal?

measured values into phasor (Module, Angle) that belongs to the
frequency domain, I mean, handle complex values is essencial.

Essential?

I know what Fourier transforms are. Thank you.
Yes I
partialy-developed using FORTRAN, but I indentified that if a OOP
approach will be used, re-using advantage could compress my source
file.


Thank you very much. I didn't realized this. Call FORTRAN like
subroutines... What good ideia.

Idea?

Good luck.
 
R

Roberto Dias

Jeff Schwab said:
Sinusoidal?
No, cosinoidal, Jeff. Because to be cosinoidal or sinusoidal depends
on the reference adopted. I choose this one. There is no incorrect
term used here.
Essential?
Thanks. This one was a "essential" comment ! He, he. I'm joking.
I know what Fourier transforms are. Thank you.
I'm sure about this. I did a non-essential comment. Sorry.
Idea? Another essential comment.

Good luck.
Jeff, I'm sorry, but there was I misunderstand. When I answer you I
was not trying to put you in prove. But the way you used to respond
me, sounded so rude and impolite, like a Bush one.
 
J

Jeff Schwab

Roberto said:
No, cosinoidal, Jeff. Because to be cosinoidal or sinusoidal depends
on the reference adopted. I choose this one. There is no incorrect
term used here.


http://dictionary.reference.com/search?q=cosinoidal

The term "sinusoidal" doesn't imply "zero phase."
Thanks. This one was a "essential" comment ! He, he. I'm joking.
:)


I'm sure about this. I did a non-essential comment. Sorry.

No problem. I just prefer to keep the discussion here centered on C++,
rather than the context of particular problems; particularly when the
technical terms in use can be looked up elsewhere.
Another essential comment.


Jeff, I'm sorry, but there was I misunderstand. When I answer you I
was not trying to put you in prove. But the way you used to respond
me, sounded so rude and impolite, like a Bush one.

:( Sorry. I know what you mean; I certainly didn't mean to come across
that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top