LAL  7.5.0.1-08ee4f4
IIRFilter.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Teviet Creighton
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #include <lal/LALStdlib.h>
21 #include <lal/IIRFilter.h>
22 
23 /**
24  * \addtogroup IIRFilter_c
25  * \author Creighton, T. D.
26  *
27  * \brief Computes an instant-by-instant IIR filter response.
28  *
29  * ### Description ###
30  *
31  * These functions pass a time-domain datum to an object <tt>*filter</tt>
32  * of type \c REAL4IIRFilter or \c REAL8IIRFilter, and return the
33  * filter response. This is done using the auxiliary data series
34  * formalism described in \ref IIRFilter_h.
35  *
36  * There are two pairs of routines in this module. The functions
37  * <tt>LALIIRFilterREAL4()</tt> and <tt>LALIIRFilterREAL8()</tt> conform to the LAL
38  * standard, with status handling and error trapping; the input datum is
39  * passed in as \c input and the response is returned in
40  * <tt>*output</tt>. The functions <tt>LALSIIRFilter()</tt> and
41  * <tt>LALDIIRFilter()</tt> are non-standard lightweight routines, which may
42  * be more suitable for multiple callings from the inner loops of
43  * programs; they have no status handling or error trapping. The input
44  * datum is passed in by the variable \c x, and the response is
45  * returned through the function's return statement.
46  *
47  */
48 /** @{ */
49 
50 /**
51  * WARNING: THIS FUNCTION IS OBSOLETE.
52  * \deprecated
53  */
54 void
56  REAL4 *output,
57  REAL4 input,
58  REAL4IIRFilter *filter )
59 {
60  INT4 j; /* Index for filter coefficients. */
61  INT4 jmax; /* Number of filter coefficients. */
62  REAL4 *coef; /* Values of filter coefficients. */
63  REAL4 *hist; /* Values of filter history. */
64 
65  INITSTATUS(stat);
66 
67  /* Check all the passed parameters for null pointers. */
68  ASSERT(output,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
69  ASSERT(filter,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
70  ASSERT(filter->directCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
71  ASSERT(filter->recursCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
72  ASSERT(filter->history,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
73  ASSERT(filter->directCoef->data,stat,IIRFILTERH_ENUL,
74  IIRFILTERH_MSGENUL);
75  ASSERT(filter->recursCoef->data,stat,IIRFILTERH_ENUL,
76  IIRFILTERH_MSGENUL);
77  ASSERT(filter->history->data,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
78 
79  /* Compute the auxiliary datum. */
80  jmax=filter->recursCoef->length;
81  coef=filter->recursCoef->data+1;
82  hist=filter->history->data;
83  for(j=1;j<jmax;j++)
84  input+=(*(coef++))*(*(hist++));
85  hist-=(jmax-1);
86 
87  /* Compute the filter output. */
88  jmax=filter->directCoef->length;
89  coef=filter->directCoef->data;
90  *output=(*(coef++))*input;
91  for(j=1;j<jmax;j++)
92  *output+=(*(coef++))*(*(hist++));
93  hist-=(jmax-1);
94 
95  /* Updata the filter history. */
96  jmax=filter->history->length-1;
97  hist+=jmax;
98  for(j=jmax;j>0;j--,hist--)
99  *hist=hist[-1];
100  *hist=input;
101 
102  /* Normal exit */
103  RETURN(stat);
104 }
105 
106 
107 /**
108  * WARNING: THIS FUNCTION IS OBSOLETE.
109  * \deprecated
110  */
111 void
113  REAL8 *output,
114  REAL8 input,
115  REAL8IIRFilter *filter )
116 {
117  INITSTATUS(stat);
118 
119  /* Check all the passed parameters for null pointers. */
120  ASSERT(output,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
121  ASSERT(filter,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
122  ASSERT(filter->directCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
123  ASSERT(filter->recursCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
124  ASSERT(filter->history,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
125  ASSERT(filter->directCoef->data,stat,IIRFILTERH_ENUL,
126  IIRFILTERH_MSGENUL);
127  ASSERT(filter->recursCoef->data,stat,IIRFILTERH_ENUL,
128  IIRFILTERH_MSGENUL);
129  ASSERT(filter->history->data,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
130 
131  *output=XLALIIRFilterREAL8(input,filter);
132 
133  /* Normal exit */
134  RETURN(stat);
135 }
136 
137 
138 /**
139  * WARNING: THIS FUNCTION IS OBSOLETE.
140  * \deprecated
141  */
142 REAL4
144 {
145  INT4 j; /* Index for filter coefficients. */
146  INT4 jmax; /* Number of filter coefficients. */
147  REAL4 *coef; /* Values of filter coefficients. */
148  REAL4 *hist; /* Values of filter history. */
149  REAL4 w; /* Auxiliary datum. */
150  REAL4 y; /* Output datum. */
151 
152  /* Compute the auxiliary datum. */
153  jmax=filter->recursCoef->length;
154  coef=filter->recursCoef->data+1;
155  hist=filter->history->data;
156  w=x;
157  for(j=1;j<jmax;j++)
158  w+=(*(coef++))*(*(hist++));
159  hist-=(jmax-1);
160 
161  /* Compute the filter output. */
162  jmax=filter->directCoef->length;
163  coef=filter->directCoef->data;
164  y=(*(coef++))*w;
165  for(j=1;j<jmax;j++)
166  y+=(*(coef++))*(*(hist++));
167  hist-=(jmax-1);
168 
169  /* Updata the filter history. */
170  jmax=filter->history->length-1;
171  hist+=jmax;
172  for(j=jmax;j>0;j--,hist--)
173  *hist=hist[-1];
174  *hist=w;
175 
176  /* Normal exit */
177  return y;
178 }
179 
180 
181 /** \see See \ref IIRFilter_c for documentation */
183 {
184  INT4 j; /* Index for filter coefficients. */
185  INT4 jmax; /* Number of filter coefficients. */
186  REAL8 *coef; /* Values of filter coefficients. */
187  REAL8 *hist; /* Values of filter history. */
188  REAL8 w; /* Auxiliary datum. */
189  REAL8 y; /* Output datum. */
190 
191  /* Compute the auxiliary datum. */
192  jmax=filter->recursCoef->length;
193  coef=filter->recursCoef->data+1;
194  hist=filter->history->data;
195  w=x;
196  for(j=1;j<jmax;j++)
197  w+=(*(coef++))*(*(hist++));
198  hist-=(jmax-1);
199 
200  /* Compute the filter output. */
201  jmax=filter->directCoef->length;
202  coef=filter->directCoef->data;
203  y=(*(coef++))*w;
204  for(j=1;j<jmax;j++)
205  y+=(*(coef++))*(*(hist++));
206  hist-=(jmax-1);
207 
208  /* Updata the filter history. */
209  jmax=filter->history->length-1;
210  hist+=jmax;
211  for(j=jmax;j>0;j--,hist--)
212  *hist=hist[-1];
213  *hist=w;
214 
215  /* Normal exit */
216  return y;
217 }
218 
219 /** \see See \ref IIRFilter_c for documentation */
221 {
222  return (REAL4)XLALIIRFilterREAL8((REAL8)x,filter);
223 }
224 /** @} */
#define ASSERT(assertion, statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
void LALIIRFilterREAL8(LALStatus *stat, REAL8 *output, REAL8 input, REAL8IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
Definition: IIRFilter.c:112
REAL4 XLALIIRFilterREAL4(REAL4 x, REAL8IIRFilter *filter)
Definition: IIRFilter.c:220
REAL8 XLALIIRFilterREAL8(REAL8 x, REAL8IIRFilter *filter)
Definition: IIRFilter.c:182
REAL4 LALSIIRFilter(REAL4 x, REAL4IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
Definition: IIRFilter.c:143
void LALIIRFilterREAL4(LALStatus *stat, REAL4 *output, REAL4 input, REAL4IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
Definition: IIRFilter.c:55
#define IIRFILTERH_ENUL
Unexpected null pointer in arguments.
Definition: IIRFilter.h:131
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947
This structure stores the direct and recursive REAL4 filter coefficients, as well as the history of t...
Definition: IIRFilter.h:152
REAL4Vector * history
The previous values of w.
Definition: IIRFilter.h:157
REAL4Vector * recursCoef
The recursive filter coefficients.
Definition: IIRFilter.h:156
REAL4Vector * directCoef
The direct filter coefficients.
Definition: IIRFilter.h:155
REAL4 * data
Pointer to the data array.
Definition: LALDatatypes.h:150
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:149
This structure stores the direct and recursive REAL8 filter coefficients, as well as the history of t...
Definition: IIRFilter.h:168
REAL8Vector * history
The previous values of w.
Definition: IIRFilter.h:173
REAL8Vector * recursCoef
The recursive filter coefficients.
Definition: IIRFilter.h:172
REAL8Vector * directCoef
The direct filter coefficients.
Definition: IIRFilter.h:171
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159
UINT4 length
Number of elements in array.
Definition: LALDatatypes.h:158
void output(int gps_sec, int output_type)
Definition: tconvert.c:440