Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

FEAPIExamplePluginZeroCrossings/zplFFT_If.cpp

Go to the documentation of this file.
00001 
00002 //     /*! \file zplFFT_If.cpp: \brief interface of the CzplFFT_If class. */
00003 //
00004 //        Copyright (c) 2004-2007  
00005 //        zplane.development
00006 //        Flohrer Lerch Schwerdtfeger GbR
00007 //        All rights reserved.
00008 //
00009 //        Redistribution and use in source and binary forms, with or without 
00010 //        modification, are permitted provided that the following conditions 
00011 //        are met:
00012 //
00013 //        *   Redistributions of source code must retain the above copyright 
00014 //            notice, this list of conditions and the following disclaimer. 
00015 //        *   Redistributions in binary form must reproduce the above 
00016 //            copyright notice, this list of conditions and the following 
00017 //            disclaimer in the documentation and/or other materials 
00018 //            provided with the distribution. 
00019 //        *   Neither the name of the FEAPI development team nor the names 
00020 //            of its contributors may be used to endorse or promote products 
00021 //            derived from this software without specific prior written 
00022 //            permission. 
00023 //
00024 //        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00025 //        "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00026 //        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00027 //        FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
00028 //        COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00029 //        INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00030 //        BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00031 //        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00032 //        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00033 //        LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00034 //        ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00035 //        POSSIBILITY OF SUCH DAMAGE.
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             // note that this is symmetric, not periodic!
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             // note that this is symmetric, not periodic!
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             // note that this is symmetric, not periodic!
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             // note that this is symmetric, not periodic!
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             // note that this is symmetric, not periodic!
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 }

Generated on Fri Mar 23 10:28:54 2007 for FEAPI Plugin Documentation by  doxygen 1.3.9.1