Hi, For a course on university I need to write some signal processing software in C++. Now, I have some experience with c++, e.g. somewhat more than the basics.
For a start I would like to take the Fourier transform of a sinus. This should be pretty straight forward:
int main(){
float *vector1;
float *vector2;
_sSCplx *vectorfft;
ofstream file ("output.m");
long int max_1=50000;
long int FFTWinSize=20;
bool RealFFT=true;
clDSPOp dsp;
This should output the sine and its FFT to a matlab file. But, instead of a nice peak I get non-frequency dependant noise, though it seems to dependant on the windowsize. Any clues or suggestions?
Thanks in advance!
Dirkjan Krijnders
student Applied Physics
Unversity of Twente
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'll write example program at weekend, but few things caught my eyes immediately.
> long int max_1=50000;
> long int FFTWinSize=20;
You have sample set of 50000, but window size of 20. First of all window size must be N=2^x where x is integer. Second, you use very short window of 20 samples for large data set.
You could use FFTWinSize=max_1=65536 and thus you would get max_1/2+1 complex values as result, as you are doing real-to-complex transform.
Best regards,
- Jussi Laako
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, For a course on university I need to write some signal processing software in C++. Now, I have some experience with c++, e.g. somewhat more than the basics.
For a start I would like to take the Fourier transform of a sinus. This should be pretty straight forward:
int main(){
float *vector1;
float *vector2;
_sSCplx *vectorfft;
ofstream file ("output.m");
long int max_1=50000;
long int FFTWinSize=20;
bool RealFFT=true;
clDSPOp dsp;
vector1=new float[max_1];
vector2=new float[max_2];
vectorfft=new _sSCplx[max_1];
generateSine(vector1,max_1,(max_1/t_max),700);
dsp.FFTInitialize(FFTWinSize,RealFFT);
dsp.FFTo(vectorfft,vector1);
file << "data = [";
for (int i=0;i<max_1;i++){
file << vectorfft[i].R <<"+"<<vectorfft[i].I << "i ";
}
file << "];" << endl;
file << "sine = [";
for (int i=0;i<max_1;i++){
file << vector1[i] << " ";
}
file << "];" << endl;
file.close();
exit(0);
}
void generateSine(float *y,int samples,float Fs,int freq){
float t;
cout << "Sine parameters:" << samples << " Sample Frequency: " << Fs << " Frequency: " <<freq << endl;
for (int i=0;i<samples;i++) {
t=((float)i/(float)Fs);
y[i]=sin(2*freq*3.1415*t);
// cout << t<< ":" << y[i] << endl;
}
}
This should output the sine and its FFT to a matlab file. But, instead of a nice peak I get non-frequency dependant noise, though it seems to dependant on the windowsize. Any clues or suggestions?
Thanks in advance!
Dirkjan Krijnders
student Applied Physics
Unversity of Twente
I'll write example program at weekend, but few things caught my eyes immediately.
> long int max_1=50000;
> long int FFTWinSize=20;
You have sample set of 50000, but window size of 20. First of all window size must be N=2^x where x is integer. Second, you use very short window of 20 samples for large data set.
You could use FFTWinSize=max_1=65536 and thus you would get max_1/2+1 complex values as result, as you are doing real-to-complex transform.
Best regards,
- Jussi Laako
I have committed working example to CVS. It's work/example1.cc, you'll also need updated DSPVector.hh to compile it.
See http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/libdsp/libDSP/