Home | Develop | Download | Contact
testprog3.c
1 /*
2  * testprog3.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  PdsFirLms *FirLms=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=2*1024;
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.01;
84  FirLms=pds_fir_lms_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  pds_fir_lms_evaluate_value(FirLms,d,x,&e,&y);
92 
93  D->V[n]=d;
94  X->V[n]=x;
95  E->V[n]=e;
96  Y->V[n]=y;
97  }
98 
99  fdh=fopen(HFILE,"w");
100  if(fdh==NULL) return EXIT_FAILURE;
101  pds_vector_fprintf(FirLms->Fir->h,fdh);
102  fclose(fdh);
103 
104  pds_fir_lms_free(FirLms);
106 
107  fd=fopen(DATAFILE,"w");
108  if(fd==NULL) return EXIT_FAILURE;
109  pds_vector_fprintf(D,fd);
110  pds_vector_fprintf(X,fd);
111  pds_vector_fprintf(E,fd);
112  pds_vector_fprintf(Y,fd);
113  fclose(fd);
114 
115  pds_octave_plot_lin(OCTAVEFILE,DATAFILE);
116  pds_octave_plot_lin_fft(OCTAVEHFILE,HFILE);
117 
118  pds_vector_free(D);
119  pds_vector_free(X);
120  pds_vector_free(E);
121  pds_vector_free(Y);
122 
123  return EXIT_SUCCESS;
124 }
PdsVector * h
Definition: pdsfir.h:80
int pds_fir_lms_evaluate_value(PdsFirLms *FirLms, PdsDfReal d, PdsDfReal x, PdsDfReal *e, PdsDfReal *y)
Evalúa el filtro FIR LMS con el valor de entrada "d" e "x", el resultado es cargado en "e" e "y"...
PdsFir * Fir
Definition: pdsfirlms.h:93
PdsFirLms * pds_fir_lms_new(PdsDfReal Mhu, PdsRaNatural M)
Crea un filtro FIR LMS con parametros h[i] del filtro FIR, con un valor inicial de h[i]=1/(1+M)...
unsigned int PdsDfNatural
Definition: pdsdfglobal.h:47
void pds_fir_lms_free(PdsFirLms *FirLms)
Libera el filtro de tipo PdsFirLms.
float PdsDfReal
Definition: pdsdfglobal.h:42
Una estructura tipo PdsFirLms .
Definition: pdsfirlms.h:86

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed