dit_pino_T.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:3k
源码类别:

3G开发

开发平台:

Visual C++

  1. //======================================================
  2. //
  3. //  File = dit_pino_T.cpp
  4. //
  5. //  Decimation-In-Time FFT
  6. //
  7. //  Permuteded Input / Naturally-ordered Output
  8. //
  9. #include <math.h>
  10. #include "misdefs.h"
  11. #include "log2.h"
  12. #include "cbitrev_T.h"
  13. #include "dit_pino_T.h"
  14. template <class T>
  15. void IfftDitPino( std::complex<T> *array,
  16.                   int fft_size)
  17. {
  18.    double trig_arg;
  19.    int log2_size;
  20.    std::complex<T> twiddle, w_fact;
  21.    std::complex<T> temp;
  22.    int pts_in_left_dft, pts_in_right_dft;
  23.    int stage, bfly_pos;
  24.    int top_node, bot_node;
  25.    log2_size = ilog2(fft_size);
  26.    pts_in_right_dft = 1;
  27.    for( stage=1; stage <=log2_size; stage++) { 
  28.       // set pts_in_left_dft = 2**(stage-1)
  29.       pts_in_left_dft = pts_in_right_dft;
  30.       // set pts_in_right_dft = 2**stage
  31.       pts_in_right_dft *= 2;
  32.       twiddle = std::complex<T>(1.0, 0.0);
  33.       trig_arg = PI/pts_in_left_dft;  
  34.       w_fact = std::complex<T>(  T(cos(trig_arg)), 
  35.                                  T(sin(trig_arg)));
  36.       for(  bfly_pos =0; 
  37.             bfly_pos < pts_in_left_dft; 
  38.             bfly_pos++){                             
  39.          for(  top_node = bfly_pos; 
  40.                top_node<fft_size; 
  41.                top_node += pts_in_right_dft){                              
  42.             bot_node = top_node + pts_in_left_dft;
  43.             temp = array[bot_node] * twiddle;
  44.             array[bot_node] = array[top_node] - temp;
  45.             array[top_node] += temp;
  46.          }
  47.          twiddle *= w_fact;
  48.       }
  49.    }
  50.    return;
  51. }
  52. //======================================================
  53. template <class T>
  54. void FftDitPino( std::complex<T> *array,
  55.                  int fft_size)
  56. {
  57.    double trig_arg;
  58.    int log2_size;
  59.    std::complex<T> twiddle, w_fact;
  60.    std::complex<T> temp;
  61.    int pts_in_left_dft, pts_in_right_dft;
  62.    int stage, bfly_pos;
  63.    int top_node, bot_node;
  64.    log2_size = ilog2(fft_size);
  65.    pts_in_right_dft = 1;
  66.    for( stage=1; stage <=log2_size; stage++) {
  67.       // set pts_in_left_dft = 2**(stage-1)
  68.       pts_in_left_dft = pts_in_right_dft; 
  69.       // set pts_in_right_dft = 2**stage
  70.       pts_in_right_dft *= 2;               
  71.       twiddle = std::complex<T>(1.0, 0.0);
  72.       trig_arg = PI/pts_in_left_dft;  
  73.       w_fact = std::complex<T>(  T(cos(trig_arg)), 
  74.                                  T(-sin(trig_arg)));
  75.       for(  bfly_pos =0; 
  76.             bfly_pos < pts_in_left_dft; 
  77.             bfly_pos++) { 
  78.          for(  top_node = bfly_pos; 
  79.                top_node<fft_size; 
  80.                top_node += pts_in_right_dft){
  81.             bot_node = top_node + pts_in_left_dft;
  82.             temp = array[bot_node] * twiddle;
  83.             array[bot_node] = array[top_node] - temp;
  84.             array[top_node] += temp;
  85.          }
  86.          twiddle *= w_fact;
  87.       }
  88.    }
  89.    return;
  90. }
  91. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
  92. template void IfftDitPino( std::complex<double> *array,
  93.                             int fft_size);
  94. template void IfftDitPino( std::complex<float> *array,
  95.                             int fft_size);
  96. template void FftDitPino( std::complex<double> *array,
  97.                            int fft_size);
  98. template void FftDitPino( std::complex<float> *array,
  99.                            int fft_size);