[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Reg :: Passing File name as argument and normalization of fft
From: |
Sumit Adhikari |
Subject: |
[Help-gsl] Reg :: Passing File name as argument and normalization of fft function. |
Date: |
Sun, 13 Sep 2009 11:54:22 +0530 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.1) Gecko/20090715 Thunderbird/3.0b3 |
Hello All,
I wrote a wrapper over gsl_fft_complex_forward and I am using it
successfully with very high reliability.
I have two questions. as follows :
1. How do I pass file-name (whatever I am dumping) as parameter ?
2. How do I normalize FFT outputs (Some how like PSD output)?
The class is as follows :
// File fft.h
# include <iostream>
using namespace std ;
# include <gsl/gsl_errno.h>
# include <gsl/gsl_fft_complex.h>
# ifndef FFT_H
# define FFT_H
# define REAL(z,i) ((z) [2*(i)])
# define IMAG(z,i) ((z) [2*(i) + 1])
namespace tools {
class fft {
public :
fft();
~fft();
void read(double data[],const int Npoints,double Fs,int DATA_DSMPLE);
};
}
# endif
// File fft.cpp
# include "fft.h"
namespace tools {
fft::fft(){}
fft::~fft(){}
void fft::read(double data[],const int Npoints,double Fs,int DATA_DSMPLE){
double *fft_data_buff ;
fft_data_buff = (double *) malloc (2*Npoints * sizeof(double));
fft_data_buff = new double [2*Npoints] ;
for (int i = 0 ; i < Npoints ;i++){
REAL(fft_data_buff,i) = data[i] ;
IMAG(fft_data_buff,i) = 0.0 ;
}
delete [] data ;
gsl_fft_complex_wavetable* wavetable ;
gsl_fft_complex_workspace* workspace ;
wavetable = gsl_fft_complex_wavetable_alloc(Npoints);
workspace = gsl_fft_complex_workspace_alloc(Npoints);
int status =
gsl_fft_complex_forward(fft_data_buff,1,Npoints,wavetable,workspace);
double *fft_out ;
fft_out = (double *) malloc (2*Npoints * sizeof(double));
fft_out = new double [2*Npoints] ;
FILE* fp_fft_data ;
fp_fft_data = fopen("./fft.dat","w");
for (int i = 0 ; i < Npoints ;i++){
fft_out[i] =
20*log10(sqrt(REAL(fft_data_buff,i)*REAL(fft_data_buff,i) +
IMAG(fft_data_buff,i)*IMAG(fft_data_buff,i))) ;
}
delete [] fft_data_buff ;
gsl_fft_complex_wavetable_free(wavetable);
gsl_fft_complex_workspace_free(workspace);
double *f ;
f = (double *) malloc (Npoints >> 1 * sizeof(double));
f = new double [Npoints >> 1] ;
for(int i = 0 ; i < (Npoints >> 1) /DATA_DSMPLE; i++){
f[i] = (Fs*i)/(Npoints );
fprintf(fp_fft_data,"%0f %0f\n",f[i],fft_out[i]);
}
fclose(fp_fft_data);
}
}
Best Regards,
--
--------------------------------------------
Sumit Adhikari
System Design Engineer
austriamicrosystems AG
Business Unit : Automotive
Mob : 00-91-9885271710/00-91-9000161710
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-gsl] Reg :: Passing File name as argument and normalization of fft function.,
Sumit Adhikari <=