Low level routine
fr - eng


nfilter_c - finite impulse response filter by discrete time convolution method computational routine

Module

Parameters

File content


/* nfilter_c subroutine
 * FIR computation
 * with classic discrete convolution method
 * Originaly write in fortran in the LARY_CR package
 * by C.Médigue, A. Monti, A. Wambergue.
 * www.inria.fr/rrrt/rt-0259.html
 * Rewrite in C and add bench of filters capability
 *
 * bugs fixed by <utug@ms.tusur.ru> , <Andy.Hutchinson@ge.com>
 *
 * Copyright (C) 2007-2011 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 "modnum_lib.h"

/* nfilter_c : routine de calcul d'un filtre à réponse impulsionnelle fini 
 *             par convolution numérique
 *
 * Entrées :
 * n      : dimension 1 des matrices d'entrée/sortie (scalaire)
 * m      : dimension 2 des matrices d'entrée/sortie (scalaire)
 * nbcoef : longueur de la réponse impulsionnelle
 * u      : pointeur sur double d'entrée (de taille n,m)
 * pulse  : pointeur sur double de la réponse impulsionelle (de taille nbcoef)
 *
 * Sorties :
 * y : pointeur sur double de sortie (de taille n,m)
 *
 * Entrées/sorties :
 * z : pointeur sur double des mémoire du filtre  (de taille nbcoef,m)
 */

void nfilter_c(int *n,int *m,int *nbcoef,double *u,double *pulse,double *y,double *z)
{
 /*déclaration*/
 double somme;
 int i,j,l;

 for(l=0;l<(*m);l++) {
   for(j=0;j<(*n);j++) {
     /*calcul sortie*/
     somme=0.;
     for(i=0;i<(*nbcoef)-1;i++) {
       somme=somme+z[l*(*nbcoef)+(*nbcoef)-1-i]*pulse[i];
     }
     somme=somme+u[l*(*n)+j]*pulse[*nbcoef-1];

     /*calcul mémoire*/
     z[l*(*nbcoef)]=u[l*(*n)+j];
     for(i=0;i<(*nbcoef)-1;i++) {
       z[l*(*nbcoef)+(*nbcoef)-i-1]=z[l*(*nbcoef)+(*nbcoef)-i-2];
     }

     /*recopie sortie dans y*/
     y[l*(*n)+j]=somme;
   }
 }
 return;
}

void nfilteri_c(int *n,int *m,int *nbcoef,int *u,double *pulse,double *y,double *z)
{
 /*déclaration*/
 double somme;
 int i,j,l;

 for(l=0;l<(*m);l++) {
   for(j=0;j<(*n);j++) {
     /*calcul sortie*/
     somme=0.;
     for(i=0;i<(*nbcoef)-1;i++) {
       somme=somme+z[l*(*nbcoef)+(*nbcoef)-1-i]*pulse[i];
     }
     somme=somme+((double) u[l*(*n)+j])*pulse[*nbcoef-1];

     /*calcul mémoire*/
     z[l*(*nbcoef)+0]=(double) u[l*(*n)+j];
     for(i=0;i<(*nbcoef)-1;i++) {
       z[l*(*nbcoef)+(*nbcoef)-i-1]=z[l*(*nbcoef)+(*nbcoef)-i-2];
     }

     /*recopie sortie dans y*/
     y[l*(*n)+j]=somme;
   }
 }

 return;
}

void nfiltery_c(int *n,int *m,int *nbcoef,double *u,double *pulse,double *y,double *z)
{
 /*déclaration*/
 double somme;
 int i,j,l;

 for(l=0;l<(*m);l++) {
   for(j=0;j<(*n);j++) {
     /*calcul sortie*/
     somme=0.;
     for(i=0;i<(*nbcoef)-1;i++) {
       somme=somme+z[l*(*nbcoef)+(*nbcoef)-1-i]*pulse[i];
     }
     somme=somme+u[l*(*n)+j]*pulse[*nbcoef-1];

     /*recopie sortie dans y*/
     y[l*(*n)+j]=somme;
   }
 }
 return;
}

void nfilterz_c(int *n,int *m,int *nbcoef,double *u,double *pulse,double *y,double *z)
{
 /*déclaration*/
 int i,j,l;

 for(l=0;l<(*m);l++) {
   for(j=0;j<(*n);j++) {
     /*calcul mémoire*/
     z[l*(*nbcoef)]=u[l*(*n)+j];
     for(i=0;i<(*nbcoef)-1;i++) {
       z[l*(*nbcoef)+(*nbcoef)-i-1]=z[l*(*nbcoef)+(*nbcoef)-i-2];
     }
   }
 }
 return;
}

Authors

A. Layec