LAL 7.6.1.1-4859cae
IIRFilterVectorR.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/**
25 * \addtogroup IIRFilterVectorR_c
26 * \author Creighton, T. D.
27 *
28 * \brief Applies a time-reversed IIR filter to a data stream.
29 *
30 * ### Description ###
31 *
32 * These functions apply a generic time-domain filter <tt>*filter</tt> to a
33 * time series <tt>*vector</tt>, as with the routines
34 * <tt>LALIIRFilterREAL4Vector()</tt>, <tt>LALIIRFilterREAL8Vector()</tt>,
35 * and <tt>LALDIIRFilterREAL4Vector()</tt>, but do so in a time-reversed
36 * manner. By successively applying normal and time-reversed IIR filters
37 * to the same data, one squares the magnitude of the frequency response
38 * while canceling the phase shift. This can be significant when one
39 * wishes to preserve phase correlations across wide frequency bands.
40 *
41 * ### Algorithm ###
42 *
43 * Because these filter routines are inherently acausal, the
44 * <tt>filter->history</tt> vector is meaningless and unnecessary. These
45 * routines neither use nor modify this data array. They effectively
46 * treat the &quot;future&quot; as zero.
47 *
48 * (An alternative implementation would be to assume that the filter
49 * &quot;history&quot; invoked by these routines, stores the \e future
50 * values of the auxiliary sequence. This would allow a large vector to
51 * be broken into chunks and time-reverse filtered, yielding the same
52 * result as if the whole vector had been time-reverse filtered. I can
53 * switch to this implementation if there is any demand for it.)
54 *
55 */
56/** @{ */
57
58#undef COMPLEX_DATA
59#undef SINGLE_PRECISION
60
61#define COMPLEX_DATA
62#define SINGLE_PRECISION
64#undef SINGLE_PRECISION
66#undef COMPLEX_DATA
67#define SINGLE_PRECISION
69#undef SINGLE_PRECISION
71
72/**
73 * WARNING: THIS FUNCTION IS OBSOLETE.
74 * \deprecated
75 */
76void
78 REAL4Vector *vector,
79 REAL4IIRFilter *filter )
80{
81 INT4 i; /* Loop counter for data vector. */
82 INT4 j; /* Index for filter coeficients. */
83 INT4 length; /* Length of vector. */
84 REAL4 *data; /* Vector data. */
85 REAL8 datum; /* Temporary working variable. */
86 INT4 directOrder; /* Number of direct filter coefficients. */
87 INT4 recursOrder; /* Number of recursive filter coefficients. */
88 REAL4 *directCoef; /* Direct filter coefficients. */
89 REAL4 *recursCoef; /* Recursive filter coefficients. */
90
91 INITSTATUS(stat);
92
93 /* Make sure all the structures have been initialized. */
94 ASSERT(vector,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
95 ASSERT(filter,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
96 ASSERT(vector->data,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
97 ASSERT(filter->directCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
98 ASSERT(filter->recursCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
100 IIRFILTERH_MSGENUL);
102 IIRFILTERH_MSGENUL);
103 length=vector->length;
104 data=vector->data+length-1;
105 directOrder=filter->directCoef->length;
106 recursOrder=filter->recursCoef->length;
107 directCoef=filter->directCoef->data;
108 recursCoef=filter->recursCoef->data;
109
110 /* Perform the auxilliary piece of the filter. */
111 for(i=0;(i<recursOrder)&&(i<length);i++,data--){
112 datum=*data;
113 for(j=1;j<=i;j++)
114 datum+=data[j]*recursCoef[j];
115 *data=datum;
116 }
117 for(;i<length;i++,data--){
118 datum=*data;
119 for(j=1;j<recursOrder;j++)
120 datum+=data[j]*recursCoef[j];
121 *data=datum;
122 }
123 data++;
124
125 /* Perform the direct piece of the filter. */
126 for(;i>directOrder;i--,data++){
127 datum=*data*directCoef[0];
128 for(j=1;j<directOrder;j++)
129 datum+=data[j]*directCoef[j];
130 *data=datum;
131 }
132 for(;i>0;i--,data++){
133 datum=*data*directCoef[0];
134 for(j=1;j<i;j++)
135 datum+=data[j]*directCoef[j];
136 *data=datum;
137 }
138
139 /* Normal exit */
140 RETURN(stat);
141}
142
143/**
144 * WARNING: THIS FUNCTION IS OBSOLETE.
145 * \deprecated
146 */
147void
149 REAL8Vector *vector,
150 REAL8IIRFilter *filter )
151{
152 INITSTATUS(stat);
153
154 /* Make sure all the structures have been initialized. */
155 ASSERT(vector,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
156 ASSERT(filter,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
157 ASSERT(vector->data,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
158 ASSERT(filter->directCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
159 ASSERT(filter->recursCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
161 IIRFILTERH_MSGENUL);
163 IIRFILTERH_MSGENUL);
164
165 if ( XLALIIRFilterReverseREAL8Vector( vector, filter ) < 0 )
166 {
168 ABORT(stat,IIRFILTERH_EMEM,IIRFILTERH_MSGEMEM);
169 }
170
171 /* Normal exit */
172 RETURN(stat);
173}
174
175/**
176 * WARNING: THIS FUNCTION IS OBSOLETE.
177 * \deprecated
178 */
179void
181 REAL4Vector *vector,
182 REAL8IIRFilter *filter )
183{
184 INITSTATUS(stat);
185
186 /* Make sure all the structures have been initialized. */
187 ASSERT(vector,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
188 ASSERT(filter,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
189 ASSERT(vector->data,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
190 ASSERT(filter->directCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
191 ASSERT(filter->recursCoef,stat,IIRFILTERH_ENUL,IIRFILTERH_MSGENUL);
193 IIRFILTERH_MSGENUL);
195 IIRFILTERH_MSGENUL);
196
197 if ( XLALIIRFilterReverseREAL4Vector( vector, filter ) < 0 )
198 {
200 ABORT(stat,IIRFILTERH_EMEM,IIRFILTERH_MSGEMEM);
201 }
202
203 /* Normal exit */
204 RETURN(stat);
205}
206/** @} */
int XLALIIRFilterReverseREAL8Vector(REAL8Vector *vector, REAL8IIRFilter *filter)
int XLALIIRFilterReverseREAL4Vector(REAL4Vector *vector, REAL8IIRFilter *filter)
#define ABORT(statusptr, code, mesg)
#define ASSERT(assertion, statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define IIRFILTERH_ENUL
Unexpected null pointer in arguments.
Definition: IIRFilter.h:131
#define IIRFILTERH_EMEM
Memory allocation error.
Definition: IIRFilter.h:133
void LALDIIRFilterREAL4VectorR(LALStatus *stat, REAL4Vector *vector, REAL8IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
void LALIIRFilterREAL4VectorR(LALStatus *stat, REAL4Vector *vector, REAL4IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
void LALIIRFilterREAL8VectorR(LALStatus *stat, REAL8Vector *vector, REAL8IIRFilter *filter)
WARNING: THIS FUNCTION IS OBSOLETE.
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).
int XLALClearErrno(void)
Clears the XLAL error number, returns the old value.
Definition: XLALError.c:363
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 * recursCoef
The recursive filter coefficients.
Definition: IIRFilter.h:156
REAL4Vector * directCoef
The direct filter coefficients.
Definition: IIRFilter.h:155
Vector of type REAL4, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:145
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 * recursCoef
The recursive filter coefficients.
Definition: IIRFilter.h:172
REAL8Vector * directCoef
The direct filter coefficients.
Definition: IIRFilter.h:171
Vector of type REAL8, see DATATYPE-Vector types for more details.
Definition: LALDatatypes.h:154
REAL8 * data
Pointer to the data array.
Definition: LALDatatypes.h:159