FE_window.cpp
上传用户:italyroyal
上传日期:2013-05-06
资源大小:473k
文件大小:2k
- ///////////////////////////////////////////////////////////////////////////////
- // This is a part of the Feature program.
- // Version: 1.0
- // Date: February 22, 2003
- // Programmer: Oh-Wook Kwon
- // Copyright(c) 2003 Oh-Wook Kwon. All rights reserved. owkwon@ucsd.edu
- ///////////////////////////////////////////////////////////////////////////////
- #include "StdAfx.h"
- #include "FE_window.h"
- #ifndef M_PI
- #define M_PI 3.14159265358979323846
- #endif
- FeWindow::FeWindow()
- {
- }
- FeWindow::~FeWindow()
- {
- }
- int FeWindow::Windowing(float *inputA, int inputN, string& wkind)
- {
- if(wkind == "Hamming")
- do_hamm_window(inputA, inputN);
- else if(wkind == "Hanning")
- do_hann_window(inputA, inputN);
- else if(wkind == "Rectangular" || wkind == "Bartlett")
- do_rect_window(inputA, inputN);
- else if(wkind == "Triangular")
- do_tri_window(inputA, inputN);
- else
- do_rect_window(inputA, inputN);
- return 1;
- }
- int FeWindow::Windowing(float *inputA, int inputN, WindowKind wkind)
- {
- if(wkind == WIN_HAMMING)
- do_hamm_window(inputA, inputN);
- else if(wkind == WIN_HANNING)
- do_hann_window(inputA, inputN);
- else if(wkind == WIN_RECT || wkind == WIN_BARTLETT)
- do_rect_window(inputA, inputN);
- else if(wkind == WIN_TRI)
- do_tri_window(inputA, inputN);
- else
- do_rect_window(inputA, inputN);
- return 1;
- }
- int FeWindow::do_hamm_window(float *inputA, int inputN)
- {
- if(hamm_window.size() != inputN){
- hamm_window.resize(inputN);
- float temp = (float)(2 * M_PI / (float)(inputN-1));
- for (int i=0 ; i<inputN ; i++ ) hamm_window[i] = (float)(0.54 - 0.46*cos(temp*i));
- }
- for (int i=0 ; i<inputN ;i++ ) inputA[i] = hamm_window[i]*inputA[i];
- return(1);
- }
- int FeWindow::do_hann_window(float *inputA, int inputN)
- {
- int i;
- if(hann_window.size() != inputN){
- hann_window.resize(inputN);
- float temp = (float)(2. * M_PI / (float)(inputN-1));
- for (i=0 ; i<inputN ; i++ ) hann_window[i] = (float)(0.5 - 0.5*cos(temp*i));
- }
- for (i=0 ; i<inputN ;i++ ) inputA[i] = hann_window[i]*inputA[i];
- return(1);
- }
- int FeWindow::do_rect_window(float *inputA, int inputN)
- {
- return(1);
- }
- int FeWindow::do_tri_window(float *inputA, int inputN)
- {
- int i;
- if(tri_window.size() != inputN){
- tri_window.resize(inputN);
- for (i=0 ; i<inputN ; i++ ) {
- if(i <= inputN/2) tri_window[i]=((2*i)/(float)inputN);
- else tri_window[i]=(2-(2*i)/(float)inputN);
- }
- }
- for (i=0 ; i<inputN ;i++ ) inputA[i] = tri_window[i]*inputA[i];
- return(1);
- }