By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

DFT routine

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Roberto Dias wrote:
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/pes...1.html#HDRXSOA

If you just want a DFT library written in C++, try Googling for a while.
Jul 22 '05 #2

P: n/a
Roberto Dias wrote:
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

Jul 22 '05 #3

P: n/a
why dont u use MATLAB.....U can use MATLAB's c++ interface to convert code
in MATLAB and get it in C++

"Roberto Dias" <di*****@br.inter.net> wrote in message
news:51**************************@posting.google.c om...
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

Jul 22 '05 #4

P: n/a
Jeff Schwab <je******@comcast.net> wrote in message news:<gc********************@comcast.com>...
Roberto Dias wrote:
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?

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.
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/pes...1.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.
Jul 22 '05 #5

P: n/a
Roberto Dias wrote:
Jeff Schwab <je******@comcast.net> wrote in message news:<gc********************@comcast.com>...
Roberto Dias wrote:
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?


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.
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/pes...1.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.


Idea?

Good luck.
Jul 22 '05 #6

P: n/a
Roberto Dias wrote:

[snip]

Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library

http://www.netwood.net/~edwin/svmtl/

and
The Object Oriented Numerics Page

http://www.oonumerics.org/oon/
Jul 22 '05 #7

P: n/a
Jeff Schwab <je******@comcast.net> wrote in message news:<3Y********************@comcast.com>...
Roberto Dias wrote:
Jeff Schwab <je******@comcast.net> wrote in message news:<gc********************@comcast.com>...
Roberto Dias wrote:

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?
When you use DFT filtering, you are interested in convert cosinoidal


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.
measured values into phasor (Module, Angle) that belongs to the
frequency domain, I mean, handle complex values is essencial.
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.
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.
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/pes...1.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.


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.
Jul 22 '05 #8

P: n/a
Roberto Dias wrote:
Jeff Schwab <je******@comcast.net> wrote in message news:<3Y********************@comcast.com>...
Roberto Dias wrote:
Jeff Schwab <je******@comcast.net> wrote in message news:<gc********************@comcast.com>...
Roberto Dias wrote:
>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?

When you use DFT filtering, you are interested in convert cosinoidal


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.

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

The term "sinusoidal" doesn't imply "zero phase."
measured values into phasor (Module, Angle) that belongs to the
frequency domain, I mean, handle complex values is essencial.


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.


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.
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.
>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/pes...1.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.


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.


:( Sorry. I know what you mean; I certainly didn't mean to come across
that way.
Jul 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.