dif_niso.cpp

来自「Digital filter designer s handbook C++ c」· C++ 代码 · 共 60 行

CPP
60
字号
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//  File = dif_niso.cpp
//
//  Decimation-In-Frequency FFT
//
//  Naturally-ordered Input / Scrambled Output
//

#include <math.h>
#include "d_cmplx.h"
#include "log2.h"
#include "misdefs.h"
#include "cbitrev.h"
#include "dif_niso.h"

void FftDifNiso( double_complex *array,
                 int fft_size)
{
double trig_arg;
int log2_size;
double_complex twiddle, w_fact;
double_complex temp;
int pts_in_left_dft, pts_in_right_dft;
int stage, bfly_pos;
int top_node, bot_node;

log2_size = ilog2(fft_size);

 pts_in_right_dft = fft_size;
 for( stage=1; stage <=log2_size; stage++)
   { 
    pts_in_left_dft = pts_in_right_dft;  // set pts_in_left_dft = N/(2**(stage-1))
    pts_in_right_dft /= 2;               // set pts_in_right_dft = N/(2**stage)
   
    twiddle = double_complex(1.0, 0.0);
    trig_arg = PI/pts_in_right_dft;  
    w_fact = double_complex(cos(trig_arg), -sin(trig_arg));
   
    for( bfly_pos =0; bfly_pos < pts_in_right_dft; bfly_pos++)
      {                             
       for( top_node = bfly_pos; top_node<fft_size; top_node += pts_in_left_dft)
         {                              
          bot_node = top_node + pts_in_right_dft;
          temp = array[top_node] + array[bot_node];
          array[bot_node] = (array[top_node] - array[bot_node]) * twiddle;
          array[top_node] = temp;
         }  // end of loop over top_node
        
       twiddle *= w_fact;
      
      } // end of loop over bfly_pos
   } // end of loop over stage

 ComplexBitReverse(array, fft_size);  

 return;
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?