Home | Develop | Download | Contact
testprog2.c
1 /*
2  * testprog2.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  PdsFir *FIR1=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(3);
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  pds_vector_set_value(h,2,1.70710678118655);
74 
75 
77  FIR1=pds_fir_new(h);
78  for(n=0;n<N;n++)
79  {
80  x=1.0+sin(M_PI*n/32.0)+sin(M_PI*n/4.0+M_PI/16.0);
81  pds_fir_evaluate_value(FIR1,x,&y);
82 
83  X->V[n]=x;
84  Y1->V[n]=y;
85  }
86  pds_fir_free(FIR1);
88 
90  FIR1=pds_fir_new(h);
91  pds_fir_evaluate_vector(FIR1,X,Y2);
92  pds_fir_free(FIR1);
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 
110 
111  FIR1=pds_fir_get_new_bandstop(40,0.3,0.7,NULL);
112  if(FIR1!=NULL)
113  {
114  printf("H:\n");
115  pds_vector_printf(pds_fir_get_h_vector(FIR1));
116  }
117 
118  PdsVector* Hw=pds_vector_new(200);
120  pds_octplot_vector_in_png(Hw,"k","|H(k)|^2","testprog2a.m","testprog2a.png");
121 
122  return EXIT_SUCCESS;
123 }
PdsVector * h
Definition: pdsfir.h:80
int pds_vector_fir_frequency_response(const PdsVector *h, PdsVector *H)
Encuentra el módulo de la respuesta en frecuencia, normalizada de 0 a pi del filtro digital conformad...
PdsFir * pds_fir_get_new_bandstop(PdsDfNatural Order, PdsDfReal Wn1, PdsDfReal Wn2, const PdsVector *Window)
Crea un filtro FIR rechaza banda, con un orden y frecuencias de corte especificados.
void pds_fir_free(PdsFir *FIR)
Libera el filtro de tipo PdsFir.
int pds_fir_evaluate_vector(PdsFir *FIR, const PdsVector *x, PdsVector *y)
Evalúa el filtro FIR con el vector de entrada x, el resultado es cargado en el vector y...
int pds_fir_evaluate_value(PdsFir *FIR, PdsDfReal x, PdsDfReal *y)
Evalúa el filtro FIR con el valor de entrada x, el resultado es cargado en y.
const PdsVector * pds_fir_get_h_vector(PdsFir *FIR)
Esta funcion retorna la dirección del vector h con los valores del filtro fir.
unsigned int PdsDfNatural
Definition: pdsdfglobal.h:47
PdsFir * pds_fir_new(const PdsVector *h)
Crea un filtro FIR con parámetros h.
Una estructura tipo PdsFir .
Definition: pdsfir.h:77
float PdsDfReal
Definition: pdsdfglobal.h:42

Enlaces de interés

HomePage Bazaar Download Bug report Ayuda Developer Feed