Home | Develop | Download | Contact
testprog6.c
1 /*
2  * testprog6.c
3  *
4  * Copyright 2011 Fernando Pujaico Rivera <fernando.pujaico.rivera@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  *
21  */
22 
23 
46 #include <config.h>
47 #include <stdlib.h>
48 #include <pds/pdsdf.h>
49 #include <pds/pdsvector.h>
50 #include "extras.h"
51 #include <math.h>
52 
53 int main(int argc, char** argv)
54 {
56  PdsFirNlms *FirNlms=NULL;
57 
58  PdsVector *D=NULL;
59  PdsVector *X=NULL;
60  PdsVector *E=NULL;
61  PdsVector *Y=NULL;
62  PdsDfReal d,x,y,e;
63  PdsDfNatural n,N;
64 
65  PdsDfNatural M;
66  PdsDfReal Mhu;
67 
68  FILE *fd=NULL;
69  char DATAFILE[]="datos.txt";
70  char OCTAVEFILE[]="plotinoctave.m";
71  FILE *fdh=NULL;
72  char HFILE[]="hdatos.txt";
73  char OCTAVEHFILE[]="plothinoctave.m";
74  N=500;
75 
76  D=pds_vector_new(N);
77  X=pds_vector_new(N);
78  Y=pds_vector_new(N);
79  E=pds_vector_new(N);
80 
81 
83  M=24; Mhu=0.8;
84  FirNlms=pds_fir_nlms_new(Mhu,M);
85  y=0; e=0;
86  for(n=0;n<N;n++)
87  {
88  x=1.0 + sin(M_PI*n/32.0) + sin(12*M_PI*n/32.0) + sin(20*M_PI*n/32.0+M_PI/16.0);
89  d= sin(M_PI*n/32.0+M_PI/128.0) + sin(12*M_PI*n/32.0) ;
90 
91  D->V[n]=d;
92  X->V[n]=x;
93  }
94 
95  pds_fir_nlms_evaluate_vector(FirNlms,D,X,E,Y);
96 
97  fdh=fopen(HFILE,"w");
98  if(fdh==NULL) return EXIT_FAILURE;
99  pds_vector_fprintf(FirNlms->Fir->h,fdh);
100  fclose(fdh);
101 
102  pds_fir_nlms_free(FirNlms);
104 
105  fd=fopen(DATAFILE,"w");
106  if(fd==NULL) return EXIT_FAILURE;
107  pds_vector_fprintf(D,fd);
108  pds_vector_fprintf(X,fd);
109  pds_vector_fprintf(E,fd);
110  pds_vector_fprintf(Y,fd);
111  fclose(fd);
112 
113  pds_octave_plot_lin(OCTAVEFILE,DATAFILE);
114  pds_octave_plot_lin_fft(OCTAVEHFILE,HFILE);
115 
116  pds_vector_free(D);
117  pds_vector_free(X);
118  pds_vector_free(E);
119  pds_vector_free(Y);
120 
121  return EXIT_SUCCESS;
122 }
PdsVector * h
Definition: pdsfir.h:80
void pds_fir_nlms_free(PdsFirNlms *FirNlms)
Libera el filtro de tipo PdsFirNlms.
int pds_fir_nlms_evaluate_vector(PdsFirNlms *FirNlms, const PdsVector *d, const PdsVector *x, PdsVector *e, PdsVector *y)
Evalúa el filtro FIR NLMS con el vector de entrada x, el resultado es cargado en el vector y...
PdsFirNlms * pds_fir_nlms_new(PdsDfReal Mhu, PdsRaNatural M)
Crea un filtro FIR NLMS con parametros h[i] del filtro FIR, con un valor inicial de h[i]=1/(1+M)...
unsigned int PdsDfNatural
Definition: pdsdfglobal.h:47
Una estructura tipo PdsFirNlms .
Definition: pdsfirnlms.h:89
float PdsDfReal
Definition: pdsdfglobal.h:42
PdsFir * Fir
Definition: pdsfirnlms.h:96

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed