/* calc_win_c subroutine * computation of coefficient for windowing fft * * Copyright (C) 2007-2009 Alan Layec * * This file is part of modnumlib. * * modnumlib is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * modnumlib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with modnumlib; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * */ /* REVISION HISTORY : * $Log$ */ #include <math.h> #include "modnum_lib.h" /* calc_win_c : calcul des coefficients de pondération * pour le fenêtrage d'une fft * * Entrées : * n : taille des vecteurs * wtyp : le type de la fenêtre (scalaire) * 1 : rectangulaire * 2 : triangulaire * 3 : hamming * 4 : hanning * autre : rectangulaire * param : paramètres de la fenêtre (vecteur) * * Sorties : * y : coefficients de la fenêtre (vecteur) * */ void calc_win_c(int *n,int *wtyp,double *param,double *y) { /*Déclaration des variables compteurs*/ int i; /*Déclaration de variables locales*/ double mid_win; double dl_win; /*calcul de l'index du milieu de la fenêtre*/ mid_win = (double)(((*n) - 1.0) / 2.0); /*convertion en double la taille de la fenêtre*/ dl_win = (double) (*n); /*sélection du type de la fenêtre*/ switch((*wtyp)) { /*rectangulaire*/ case 1 : for(i=0;i<(*n);i++) { y[i] = 1.0; } break; /*triangulaire*/ case 2 : for(i=0;i<(*n);i++) { y[i] = 1.0 - \ 2.0 * (Abs(-mid_win + i)) / (dl_win+1.0); } break; /*hamming*/ case 3 : for(i=0;i<(*n);i++) { y[i] = 0.54 + \ 0.46*cos(2.0*M_PI*(-mid_win + i) / (dl_win+1.0)); } break; /*hanning*/ case 4 : for(i=0;i<(*n);i++) { y[i] = 0.5 + \ 0.5*cos(2.0*M_PI*(-mid_win + i) / (dl_win+1.0)); } break; /*rectangulaire*/ default : for(i=0;i<(*n);i++) { y[i] = 1.0; } break; } return; }