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