Home | Develop | Download | Contact
testprog7.c
1 /*
2  * testprog7.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 
42 #include <config.h>
43 #include <stdlib.h>
44 #include <pds/pdsdf.h>
45 #include <pds/pdsvector.h>
46 #include "extras.h"
47 #include <math.h>
48 
49 int main(int argc, char** argv)
50 {
52  PdsLpFir *LPFIR1=NULL;
53  PdsVector *h=NULL;
54  PdsVector *X=NULL;
55  PdsVector *Y1=NULL;
56  PdsVector *Y2=NULL;
57  PdsDfReal x,y;
58  PdsDfNatural n,N;
59  FILE *fd=NULL;
60  char DATAFILE[]="datos.txt";
61  char OCTAVEFILE[]="plotinoctave.m";
62 
63  N=128;
64 
65  h=pds_vector_new(2);
66  X=pds_vector_new(N);
67  Y1=pds_vector_new(N);
68  Y2=pds_vector_new(N);
69 
70  /* h=[ 1.70710678118655 -2.41421356237310 1.70710678118655] */
71  pds_vector_set_value(h,0,1.70710678118655);
72  pds_vector_set_value(h,1,-2.41421356237310);
73 
74 
76  LPFIR1=pds_lpfir_new(h,FALSE);
77  for(n=0;n<N;n++)
78  {
79  x=1.0+sin(M_PI*n/32.0)+sin(M_PI*n/4.0+M_PI/16.0);
80  pds_lpfir_evaluate_value(LPFIR1,x,&y);
81 
82  X->V[n]=x;
83  Y1->V[n]=y;
84  }
85  pds_lpfir_free(LPFIR1);
87 
88 
90  LPFIR1=pds_lpfir_new(h,FALSE);
91  pds_lpfir_evaluate_vector(LPFIR1,X,Y2);
92  pds_lpfir_free(LPFIR1);
94 
95 
96  fd=fopen(DATAFILE,"w");
97  if(fd==NULL) return EXIT_FAILURE;
98  pds_vector_fprintf(X,fd);
99  pds_vector_fprintf(Y1,fd);
100  pds_vector_fprintf(Y2,fd);
101  fclose(fd);
102 
103  pds_octave_plot_lin(OCTAVEFILE,DATAFILE);
104 
105  pds_vector_free(Y2);
106  pds_vector_free(Y1);
107  pds_vector_free(X);
108  pds_vector_free(h);
109  return EXIT_SUCCESS;
110 }
int pds_lpfir_evaluate_value(PdsLpFir *LPFIR, PdsDfReal x, PdsDfReal *y)
Evalúa el filtro Linear-Phase FIR con el valor de entrada x, el resultado es cargado en y...
Una estructura tipo PdsLpFir .
Definition: pdslpfir.h:95
PdsLpFir * pds_lpfir_new(const PdsVector *h, PdsDfNatural par)
Crea un filtro Linear-Phase FIR con parametros h.
int pds_lpfir_evaluate_vector(PdsLpFir *LPFIR, const PdsVector *x, PdsVector *y)
Evalúa el filtro Linear-Phase FIR con el vector de entrada x, el resultado es cargado en el vector y...
unsigned int PdsDfNatural
Definition: pdsdfglobal.h:47
void pds_lpfir_free(PdsLpFir *LPFIR)
Libera el filtro de tipo PdsLpFir.
float PdsDfReal
Definition: pdsdfglobal.h:42

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed