Home | Develop | Download | Contact
example1b.c
1 /*
2  * example1b.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 
41 #include <config.h>
42 #include <stdlib.h>
43 #include <pds/pdsdf.h>
44 #include <pds/pdsvector.h>
45 #include "extras.h"
46 #include <math.h>
47 
48 int main(int argc, char** argv)
49 {
51  PdsIir *IIR1=NULL;
52  PdsVector *hden=NULL;
53  PdsVector *hnum=NULL;
54  PdsDfReal x,y;
55  PdsDfNatural n,N;
56  FILE *fd=NULL;
57  char DATAFILE[]="datos.txt";
58  char OCTAVEFILE[]="plotinoctave.m";
59  PdsVector *X=NULL;
60  PdsVector *Y1=NULL;
61  PdsVector *Y2=NULL;
62 
63 
64  //-------------------------- Creando filtro IIR --------------------------//
65 
66  // hnum=[ 1/20 1/20]
67  PdsRaReal num[]={1/20.0,1/20.0};
68  hnum=pds_vector_new_array1d(num,2);
69 
70  // hden=[1.0 -0.9]
71  PdsRaReal den[]={1.0 ,-0.9 };
72  hden=pds_vector_new_array1d(den,2);
73 
74  IIR1=pds_iir_new(hnum,hden);
75  //------------------------------------------------------------------------//
76 
77 
78  N=128;
79  X=pds_vector_new(N);
80  Y1=pds_vector_new(N);
81 
82 
83  for(n=0;n<N;n++)
84  {
85  x=1.0+sin(M_PI*n/32.0)+sin(3.0*M_PI*n/4.0+M_PI/16.0);
86  pds_iir_evaluate_value(IIR1,x,&y);
87 
88  X->V[n]=x;
89  Y1->V[n]=y;
90  }
91  pds_iir_free(IIR1);
93 
94  Y2=pds_vector_new(N);
96  IIR1=pds_iir_new(hnum,hden);
97  pds_iir_evaluate_vector(IIR1,X,Y2);
98  pds_iir_free(IIR1);
100 
101  fd=fopen(DATAFILE,"w");
102  if(fd==NULL) return EXIT_FAILURE;
103  pds_vector_fprintf(X,fd);
104  pds_vector_fprintf(Y1,fd);
105  pds_vector_fprintf(Y2,fd);
106  fclose(fd);
107 
108  pds_octave_plot_lin(OCTAVEFILE,DATAFILE);
109 
110  pds_vector_free(hnum);
111  pds_vector_free(hden);
112  return EXIT_SUCCESS;
113 }
int pds_iir_evaluate_value(PdsIir *IIR, PdsDfReal x, PdsDfReal *y)
Evalua el filtro IIR con el valor de entrada x, el resultado es cargado en y.
void pds_iir_free(PdsIir *IIR)
Libera el filtro de tipo PdsIir.
int pds_iir_evaluate_vector(PdsIir *IIR, const PdsVector *x, PdsVector *y)
Evalua el filtro IIR con el vector de entrada x, el resultado es cargado en el vector y...
unsigned int PdsDfNatural
Definition: pdsdfglobal.h:47
Una estructura tipo PdsIir .
Definition: pdsiir.h:86
float PdsDfReal
Definition: pdsdfglobal.h:42
PdsIir * pds_iir_new(const PdsVector *hnum, const PdsVector *hden)
Crea un filtro IIR con parametros hnum y hden.

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed