1 """Compiled routines for filtering.
2
3 Copyright 2008-2011 Research Foundation State University of New York
4 This file is part of QUB Express.
5
6 QUB Express 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 3 of the License, or
9 (at your option) any later version.
10
11 QUB Express 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 named LICENSE.txt, in the QUB Express program directory. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 """
21
22 from qubx.fast.fast_utils import *
23
24 qubfast.qub_filterdatad.argtypes = (c_double_p, c_double_p, c_int, c_double, c_double)
25 qubfast.qub_filterdatad.restype = c_int
26 qubfast.qub_filterdataf.argtypes = (c_float_p, c_float_p, c_int, c_float, c_float)
27 qubfast.qub_filterdataf.restype = c_int
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 -def filter(samples, sampling_sec, freq_Hz):
83 """Returns a numpy.array of samples, low-pass filtered at freq_Hz."""
84
85
86
87
88
89
90 try:
91 dtype = samples.dtype
92 except:
93 dtype = None
94 if dtype == numpy.float32:
95 output = numpy.zeros(shape=samples.shape, dtype=numpy.float32)
96 qubfast.qub_filterdataf(samples.ctypes.data_as(c_float_p), output.ctypes.data_as(c_float_p),
97 len(samples), sampling_sec, freq_Hz)
98 return output
99 elif dtype == numpy.float64:
100 output = numpy.zeros(shape=samples.shape, dtype=numpy.float64)
101 qubfast.qub_filterdatad(samples.ctypes.data_as(c_double_p), output.ctypes.data_as(c_double_p),
102 len(samples), sampling_sec, freq_Hz)
103 return output
104 else:
105 input = numpy.array(samples, dtype=numpy.float32)
106 output = numpy.zeros(shape=samples.shape, dtype=numpy.float32)
107 qubfast.qub_filterdataf(input.ctypes.data_as(c_float_p), output.ctypes.data_as(c_float_p),
108 len(samples), sampling_sec, freq_Hz)
109 return output
110
111
112 qubfast.DFII32_New.argtypes = ()
113 qubfast.DFII32_New.restype = c_void_p
114 qubfast.DFII32_Free.argtypes = (c_void_p,)
115 qubfast.DFII32_Free.restype = None
116 qubfast.DFII32_Init.argtypes = (c_char_p, c_void_p, c_float)
117 qubfast.DFII32_Init.restype = c_int
118 qubfast.DFII32.argtypes = (c_float, c_void_p)
119 qubfast.DFII32.restype = c_float
120
126 - def init(self, filename, initial_val=0.0):
127 return bool(qubfast.DFII32_Init(filename, self.obj, initial_val))
132
133
134 qubfast.DFII64_New.argtypes = ()
135 qubfast.DFII64_New.restype = c_void_p
136 qubfast.DFII64_Free.argtypes = (c_void_p,)
137 qubfast.DFII64_Free.restype = None
138 qubfast.DFII64_Init.argtypes = (c_char_p, c_void_p, c_double)
139 qubfast.DFII64_Init.restype = c_int
140 qubfast.DFII64.argtypes = (c_double, c_void_p)
141 qubfast.DFII64.restype = c_double
142
148 - def init(self, filename, initial_val=0.0):
149 return bool(qubfast.DFII64_Init(filename, self.obj, initial_val))
154