/* Modnumlib Scicos interfacing function * Copyright (C) 2009-2011 Alan Layec * * This library 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. * * This library 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 this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ /* nfilter Scicos Temporal RIF block * Type 4 simulation function ver 1.0 - scilab-2.6&2.7 * 13 octobre 2003 - IRCOM GROUP - Author : A.Layec * 17 janvier 2005 : passage type 4 */ /* REVISION HISTORY : * $Log$ */ #include "modnum_lib.h" #include "scicos_block.h" /* Cette fonction de simulation réalise le filtrage temporel * par réponse impulsionnelle finie. * Elle est capable de réaliser le produit de convolution * d'un vecteur d'entrée par un vecteur des réponses impulsionnelles. * Pour l'instant, le vecteur des réponses impulsionnelles est de taille fixe (nb_coef) * pour chaque filtre mais chaque réponse impulsionnelle peut avoir une forme différente. * * L'opération réalisée est * y[][k]=rpar[][k]*u[][k] où * représente ici le produit de convolution discret. * a chaque rythme d'échantillonnage la valeur de u[][k] est stocké dans z[][k] * et la valeur de y[][k] est calculée * * entrées régulières : vecteur des échantillons des signaux d'entrées u[0..Nu-1]. * sortie régulières : vecteur des échantillons des signaux filtrés y[0..Nu-1]. * entrée évènementielles : fréquence d'échantillonnage. * sorties évènementielles : néant. * paramètres réels : * rpar[0..nbcoef-1,nbcoef..2*nbcoef-1,...,(Nu-1)*nbcoef-1..Nu*nbcoef-1] : vecteur des réponses impulsionnelles * paramètres entiers : * ipar[0] : nbcoef : nombre de coefficients de la réponse impulsionnelle * insz[0] : Nu : nombre de signaux à filtrer * Vecteur Z : * z[0..nbcoef-1,nbcoef..2*nbcoef-1,...,(Nu-1)*nbcoef-1..Nu*nbcoef-1] = * u[0][k-nbcoef-1],u[0][k-nbcoef-2],..,u[0][k],...,u[Nu-1][k-nbcoef-1],u[Nu-1][k-nbcoef-2],..,u[Nu-1][k] */ /*prototype*/ void nfilter(scicos_block *block,int flag) { /*déclaration des variables*/ double *y; double *u; int *sz,*nbcoef; int i,nu; int mu; int ptrui,ptrz; /*récupération des adresses des ports*/ y=(double *)block->outptr[0]; u=(double *)block->inptr[0]; /*récupération des paramètres*/ nu=block->ipar[0]; mu=1; nbcoef=&block->ipar[1]; sz=&block->ipar[1+nu]; if(flag==1) { ptrui=0; ptrz=0; for (i=0;i<nu;i++) { /*Appel nfilter*/ nfiltery_c(&sz[i],&mu,&nbcoef[i],&u[ptrui],&block->rpar[ptrz],&y[ptrui],&block->z[ptrz]); if(nu>1) { ptrui=sz[i]; ptrz=nbcoef[i]; } } } else if(flag==2) { ptrui=0; ptrz=0; for (i=0;i<nu;i++) { /*Appel nfilterz*/ nfilterz_c(&sz[i],&mu,&nbcoef[i],&u[ptrui],&block->rpar[ptrz],&y[ptrui],&block->z[ptrz]); if(nu>1) { ptrui=sz[i]; ptrz=nbcoef[i]; } } } }