windowcalc.c

来自「基于8051F单片机,实现1024点的FFT 用C 语言实现的.效果与FPGA」· C语言 代码 · 共 79 行

C
79
字号


#include "FFT_Code_Tables.h"




//-----------------------------------------------------------------------------
// WindowCalc
//-----------------------------------------------------------------------------
//
// Uses the values in WindowFunc[] to window the stored data.
//
// The WindowFunc[] Array contains window coefficients between samples
// 0 and (NUM_FFT/2)-1, and samples from NUM_FFT/2 to NUM_FFT-1 are the mirror
// image of the other side.
// Window values are interpreted as a fraction of 1 (WindowFunc[x]/65536).
// The value at NUM_FFT/2 is assumed to be 1.0 (65536).
//
// If SE_data = 1, the input data is assumed to be single-ended, and is
// converted to a 2's complement, differential representation, to cancel the DC
// offset.
//
void WindowCalc(int Win_Array[], unsigned char SE_data)
{

#if (WINDOW_TYPE != 0)  // Use this section if a window has been specified
  
    IBALONG NewVal;

   if (SE_data)                              // If data is single-ended,
      Win_Array[0] ^= 0x8000;                // convert it to differential
   NewVal.l = (long)Win_Array[0] * WindowFunc[0];
  
   if ((NewVal.l < 0)&&(NewVal.i[1]))
     Win_Array[0] = NewVal.i[0] + 1;
   else Win_Array[0] = NewVal.i[0];

   if (SE_data)                              // If data is single-ended,
      Win_Array[NUM_FFT/2] ^= 0x8000;        // convert it to differential

  for (index = 1; index < NUM_FFT/2; index++)
  {
      // Array positions 1 to (NUM_FFT/2 - 1)
      if (SE_data)                           // If data is single-ended,
         Win_Array[index] ^= 0x8000;         // convert it to differential
      NewVal.l = (long)Win_Array[index] * WindowFunc[index];
      if ((NewVal.l < 0)&&(NewVal.i[1]))
        Win_Array[index] = NewVal.i[0] + 1;

 else Win_Array[index] = NewVal.i[0];

      // Array positions (NUM_FFT/2 + 1) to (NUM_FFT - 1)
      if (SE_data)                           // If data is single-ended,
         Win_Array[NUM_FFT-index] ^= 0x8000; // convert it to differential
      NewVal.l = (long)Win_Array[NUM_FFT-index] * WindowFunc[index];
    
	  if ((NewVal.l < 0)&&(NewVal.i[1]))
         Win_Array[NUM_FFT-index] = NewVal.i[0] + 1;
      else Win_Array[NUM_FFT-index] = NewVal.i[0];

   }

#endif

#if (WINDOW_TYPE == 0)  // Compile this if no window has been specified

   if (SE_data)                              // If data is single-ended,
   {                                         // convert it to differential

      for (index = 0; index < NUM_FFT; index++)
      {
         Win_Array[index] ^= 0x8000;         // XOR MSB with '1' to invert
      }
   }

#endif

}  // END WindowCalc

⌨️ 快捷键说明

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