00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00038 
00039 #include <string.h>
00040 #include <math.h>
00041 
00042 #include "zplVecLib.h"
00043 
00044 #if !defined(_2PI)
00045 #define _2PI                    (float)(6.283185307179586476925286766559)    
00046 #endif
00047 
00048 void CzplfFFT_If::CalculateWindow (_Fft_Windows_ eWindowType)
00049 {
00050     int i = 0;
00051 
00052     ZASSERT (!m_pfWindow);
00053     ZASSERT (m_iBlockLength < 4);
00054 
00055     switch (eWindowType)   
00056     {
00057     default:
00058     case _RECT:
00059         {
00060             for (i = 0; i < m_iBlockLength; i++)
00061                 m_pfWindow[i]   = 1.0F;
00062             break;
00063         }
00064     case _HANNING:
00065         {
00066             
00067             for (i = 0; i < m_iBlockLength; i++)
00068                 m_pfWindow[i]   = .5F * (1.0F - cosf (_2PI * (i+1) / (m_iBlockLength+1)));
00069             break;
00070         }
00071     case _HAMMING:
00072         {
00073             
00074             for (i = 0; i < m_iBlockLength; i++)
00075                 m_pfWindow[i]   = .54F - .46F * cosf (_2PI * i / (m_iBlockLength-1));
00076             break;
00077         }
00078     case _BLACKMAN:
00079         {
00080             
00081             for (i = 0; i < m_iBlockLength; i++)
00082                 m_pfWindow[i]   = .42F - .5F * cosf (_2PI * i / (m_iBlockLength-1)) + .08F * cosf (2*_2PI * i / (m_iBlockLength-1));
00083             break;
00084         }
00085     case _BARTLETT:
00086         {
00087             
00088             for (i = 0; i < (m_iBlockLength>>1); i++)
00089             {
00090                 m_pfWindow[i]                       =  1 - (-i + (m_iBlockLength-1)*.5F) / (.5F*(m_iBlockLength-1));
00091                 m_pfWindow[m_iBlockLength - 1 - i]  = m_pfWindow[i];
00092             }
00093             break;
00094         }
00095     case _WELCH:
00096         {
00097             
00098             for (i = 0; i < (m_iBlockLength>>1); i++)
00099             {
00100                 m_pfWindow[i]                       =  1 - (-i + (m_iBlockLength-1)*.5F) / (.5F*(m_iBlockLength-1));
00101                 m_pfWindow[i]                      *= m_pfWindow[i];
00102                 m_pfWindow[m_iBlockLength - 1 - i]  = m_pfWindow[i];
00103             }
00104             break;
00105         }
00106     }
00107 }
00108 
00109 unsigned int CzplfFFT_If::Log2 (int iValueAsPowOf2)
00110 {
00111     unsigned int    iOrder = 0;
00112 
00113     while (iValueAsPowOf2>>iOrder)
00114         iOrder++;
00115 
00116     if (!(iValueAsPowOf2%(1<<(iOrder-1))))
00117         iOrder--;
00118     
00119     return iOrder;
00120 }
00121 
00122 int CzplfFFT_If::zplfGetWindow (float *pfWindow)
00123 {
00124     if (!pfWindow)
00125         return m_iBlockLength;
00126     else
00127     {
00128         memcpy (pfWindow, m_pfWindow, sizeof(float) * m_iBlockLength);
00129         return m_iBlockLength;
00130     }
00131 }