Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
IIRFilterVector_source.c
Go to the documentation of this file.
1#define CONCAT2x(a,b) a##b
2#define CONCAT2(a,b) CONCAT2x(a,b)
3#define STRING(a) #a
4
5#ifdef COMPLEX_DATA
6# define DBLDATATYPE COMPLEX16
7# ifdef SINGLE_PRECISION
8# define DATATYPE COMPLEX8
9# else
10# define DATATYPE COMPLEX16
11# endif
12#else
13# define DBLDATATYPE REAL8
14# ifdef SINGLE_PRECISION
15# define DATATYPE REAL4
16# else
17# define DATATYPE REAL8
18# endif
19#endif
20
21
22#define VECTORTYPE CONCAT2(DATATYPE,Vector)
23#define FILTERTYPE CONCAT2(DBLDATATYPE,IIRFilter)
24
25#define FUNC CONCAT2(XLALIIRFilter,VECTORTYPE)
26
27int FUNC(VECTORTYPE *vector, FILTERTYPE *filter)
28{
29 INT4 j; /* Index for filter coeficients. */
30 INT4 length; /* Length of vector. */
31 DATATYPE *data; /* Vector data. */
32 DBLDATATYPE w, datum; /* Current auxiliary and output values. */
33 INT4 directOrder; /* Number of direct filter coefficients. */
34 INT4 recursOrder; /* Number of recursive filter coefficients. */
35 INT4 numHist; /* The number of history data. */
36 REAL8 *directCoef; /* Direct filter coefficients. */
37 REAL8 *recursCoef; /* Recursive filter coefficients. */
38 DBLDATATYPE *temp=NULL; /* Temporary storage for the filter history. */
39
40 /* Make sure all the structures have been initialized. */
41 if ( ! vector || ! filter )
43 if ( ! vector->data )
45 if ( ! filter->directCoef || ! filter->recursCoef || ! filter->history
46 || ! filter->directCoef->data || ! filter->recursCoef->data
47 || ! filter->history->data )
49
50 length=vector->length;
51 data=vector->data;
52 directOrder=filter->directCoef->length;
53 recursOrder=filter->recursCoef->length;
54 directCoef=filter->directCoef->data;
55 recursCoef=filter->recursCoef->data;
56 numHist=filter->history->length+1;
57 temp = LALMalloc( numHist*sizeof(*temp) );
58 if ( ! temp )
60 memcpy(temp,filter->history->data,(numHist-1)*sizeof(*temp));
61
62 /* Run through the vector. */
63 while(length--){
64
65 /* Compute the auxiliary variable. */
66 for(j=numHist-1;j>=recursOrder;j--)
67 temp[j]=temp[j-1];
68 w=*data;
69 for(;j;j--)
70 w+=recursCoef[j]*(temp[j]=temp[j-1]);
71
72 /* Compute filter output. */
73 datum=*directCoef*(*temp=w);
74 for(j=1;j<directOrder;j++)
75 datum+=directCoef[j]*temp[j];
76 *(data++)=datum;
77 }
78
79 /* Update the history. */
80 memcpy(filter->history->data,temp,(numHist-1)*sizeof(*temp));
81 LALFree(temp);
82
83 /* Normal exit */
84 return 0;
85}
86
87#undef FUNC
88#undef VECTORTYPE
89#undef FILTERTYPE
90#undef DBLDATATYPE
91#undef DATATYPE
92#undef CONCAT2x
93#undef CONCAT2
94#undef STRING
#define DBLDATATYPE
#define DATATYPE
#define FILTERTYPE
#define FUNC
#define VECTORTYPE
#define LALMalloc(n)
Definition: LALMalloc.h:93
#define LALFree(p)
Definition: LALMalloc.h:96
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
#define XLAL_ERROR(...)
Macro to invoke a failure from a XLAL routine returning an integer.
Definition: XLALError.h:700
@ XLAL_ENOMEM
Memory allocation error.
Definition: XLALError.h:407
@ XLAL_EFAULT
Invalid pointer.
Definition: XLALError.h:408
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409