help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] FFT(INVFFT) is not returning original data!


From: Sumit Adhikari
Subject: [Help-gsl] FFT(INVFFT) is not returning original data!
Date: Mon, 11 Jan 2010 15:22:25 +0530

Hello All,
  Following function is returning me the original data. Can anybody please
tell me what is the problem I am doing with it ?


# ifndef SC_FFT_H
# define SC_FFT_H

# include <cmath>

# include "systemc.h"

# include "m_signal_inout_if.h"
# include "m_signal_in_if.h"


# include <gsl/gsl_errno.h>
# include <gsl/gsl_fft_complex.h>

# include "hann.h"


# define REAL(z,i) ((z) [2*(i)])
# define IMAG(z,i) ((z) [2*(i) + 1])

template < typename T > class sc_fft : public sc_module {
public :
   sc_port < m_signal_in_if < T > >          inp ;
   sc_port < m_signal_inout_if < T > >       out ;
   sc_port < m_signal_inout_if < bool > >    tx  ;
   sc_port < m_signal_inout_if < T > >       freq;


   typedef sc_fft SC_CURRENT_USER_MODULE ;

   sc_fft(sc_module_name name,const unsigned Nfft,T Offset):
      inp("inp"),
      out("out"),
      tx("tx"),
      freq("freq"),
      sc_module(name),
      _Nfft(Nfft) ,
      _Offset(Offset) {

         Npoints = _Nfft ;

         i = 0 ;

         fft_inp_buff = (double*) malloc (_Nfft * sizeof(double));
         fft_inp_buff = new double [_Nfft] ;

         fft_trn_buff = (double*) malloc (2*_Nfft * sizeof(double));
         fft_trn_buff = new double [2*_Nfft] ;

         fft_out_buff = (double*) malloc (_Nfft * sizeof(double));
         fft_out_buff = new double [_Nfft] ;


         SC_METHOD(read);
         sensitive << inp ;
      }


private :
   const unsigned       _Nfft          ;
   T                    _Offset        ;
   unsigned             Npoints        ;
   unsigned             i              ;
   double*              fft_inp_buff   ;
   double*              fft_trn_buff   ;
   double*              fft_out_buff ;


   void inline read(){
      if (i == (Npoints - 1)) {
         i = 0 ;

         for(int j = 0 ; j < Npoints ; j++) {
            REAL(fft_trn_buff,j) = fft_inp_buff[j];
            IMAG(fft_trn_buff,j) = 0.0 ;
         }

         int fstatus =
gsl_fft_complex_radix2_forward(fft_trn_buff,1,Npoints);
         int rstatus =
gsl_fft_complex_radix2_inverse(fft_trn_buff,1,Npoints);
         for(int j = 0 ; j < Npoints ; j++) fft_out_buff[j] =
sqrt(REAL(fft_trn_buff,j)*REAL(fft_trn_buff,j) +
IMAG(fft_trn_buff,j)*IMAG(fft_trn_buff,j)) ;


         fft_inp_buff[i] = (double) (inp->read() - _Offset);
         out->write((T) fft_out_buff[i]);
         tx->write(true);

      }
      else {
         i ++ ;

         fft_inp_buff[i] = (double) (inp->read() - _Offset) ;
         out->write((T) fft_out_buff[i]);
         tx->write(false);
      }

      freq->write((T) i);
   }


};


# endif

Regards,

Sumit


reply via email to

[Prev in Thread] Current Thread [Next in Thread]