3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, gr_unittest
26 class qa_filter_delay_fc (gr_unittest.TestCase):
29 self.fg = gr.flow_graph ()
34 def test_001_filter_delay_one_input (self):
37 expected_result = ( -1.4678005338941702e-11j,
38 -0.0011950774351134896j,
39 -0.0019336787518113852j,
40 -0.0034673355985432863j,
41 -0.0036765895783901215j,
42 -0.004916108213365078j,
43 -0.0042778430506587029j,
44 -0.006028641015291214j,
45 -0.005476709920912981j,
46 -0.0092810001224279404j,
47 -0.0095402700826525688j,
48 -0.016060983762145042j,
49 -0.016446959227323532j,
50 -0.02523401565849781j,
51 -0.024382550269365311j,
52 -0.035477779805660248j,
53 -0.033021725714206696j,
54 -0.048487484455108643j,
55 -0.04543270543217659j,
56 -0.069477587938308716j,
57 -0.066984444856643677j,
58 -0.10703597217798233j,
59 -0.10620346665382385j,
61 -0.19357112050056458j,
62 (7.2191945754696007e-09 -0.50004088878631592j),
63 (0.58778399229049683 -0.6155126690864563j),
64 (0.95105588436126709 -0.12377222627401352j),
65 (0.95105588436126709 +0.41524654626846313j),
66 (0.5877838134765625 +0.91611981391906738j),
67 (5.8516356205018383e-09 +1.0670661926269531j),
68 (-0.5877840518951416 +0.87856143712997437j),
69 (-0.95105588436126709 +0.35447561740875244j),
70 (-0.95105588436126709 -0.26055556535720825j),
71 (-0.5877838134765625 -0.77606213092803955j),
72 (-8.7774534307527574e-09 -0.96460390090942383j),
73 (0.58778399229049683 -0.78470128774642944j),
74 (0.95105588436126709 -0.28380891680717468j),
75 (0.95105588436126709 +0.32548999786376953j),
76 (0.5877838134765625 +0.82514488697052002j),
77 (1.4629089051254596e-08 +1.0096219778060913j),
78 (-0.5877840518951416 +0.81836479902267456j),
79 (-0.95105588436126709 +0.31451958417892456j),
80 (-0.95105588436126709 -0.3030143678188324j),
81 (-0.5877838134765625 -0.80480599403381348j),
82 (-1.7554906861505515e-08 -0.99516552686691284j),
83 (0.58778399229049683 -0.80540722608566284j),
84 (0.95105582475662231 -0.30557557940483093j),
85 (0.95105588436126709 +0.31097668409347534j),
86 (0.5877838134765625 +0.81027895212173462j),
87 (2.3406542482007353e-08 +1.0000816583633423j),
88 (-0.5877840518951416 +0.80908381938934326j),
89 (-0.95105588436126709 +0.30904293060302734j),
90 (-0.95105588436126709 -0.30904296040534973j),
91 (-0.5877838134765625 -0.80908387899398804j),
92 (-2.6332360292258272e-08 -1.0000815391540527j),
93 (0.58778399229049683 -0.80908381938934326j),
94 (0.95105582475662231 -0.30904299020767212j),
95 (0.95105588436126709 +0.30904293060302734j),
96 (0.5877838134765625 +0.80908381938934326j),
97 (3.218399768911695e-08 +1.0000815391540527j))
104 src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,
105 sampling_freq * 0.10, 1.0)
106 head = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10))
107 dst2 = gr.vector_sink_c ()
110 taps = gr.firdes_hilbert (ntaps)
111 hd = gr.filter_delay_fc (taps)
113 fg.connect (src1, head)
114 fg.connect (head, hd)
120 result_data = dst2.data ()
121 self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5)
123 def test_002_filter_delay_two_inputs (self):
125 # giving the same signal to both the inputs should fetch the same results
129 expected_result = ( -1.4678005338941702e-11j,
130 -0.0011950774351134896j,
131 -0.0019336787518113852j,
132 -0.0034673355985432863j,
133 -0.0036765895783901215j,
134 -0.004916108213365078j,
135 -0.0042778430506587029j,
136 -0.006028641015291214j,
137 -0.005476709920912981j,
138 -0.0092810001224279404j,
139 -0.0095402700826525688j,
140 -0.016060983762145042j,
141 -0.016446959227323532j,
142 -0.02523401565849781j,
143 -0.024382550269365311j,
144 -0.035477779805660248j,
145 -0.033021725714206696j,
146 -0.048487484455108643j,
147 -0.04543270543217659j,
148 -0.069477587938308716j,
149 -0.066984444856643677j,
150 -0.10703597217798233j,
151 -0.10620346665382385j,
152 -0.1852707713842392j,
153 -0.19357112050056458j,
154 (7.2191945754696007e-09 -0.50004088878631592j),
155 (0.58778399229049683 -0.6155126690864563j),
156 (0.95105588436126709 -0.12377222627401352j),
157 (0.95105588436126709 +0.41524654626846313j),
158 (0.5877838134765625 +0.91611981391906738j),
159 (5.8516356205018383e-09 +1.0670661926269531j),
160 (-0.5877840518951416 +0.87856143712997437j),
161 (-0.95105588436126709 +0.35447561740875244j),
162 (-0.95105588436126709 -0.26055556535720825j),
163 (-0.5877838134765625 -0.77606213092803955j),
164 (-8.7774534307527574e-09 -0.96460390090942383j),
165 (0.58778399229049683 -0.78470128774642944j),
166 (0.95105588436126709 -0.28380891680717468j),
167 (0.95105588436126709 +0.32548999786376953j),
168 (0.5877838134765625 +0.82514488697052002j),
169 (1.4629089051254596e-08 +1.0096219778060913j),
170 (-0.5877840518951416 +0.81836479902267456j),
171 (-0.95105588436126709 +0.31451958417892456j),
172 (-0.95105588436126709 -0.3030143678188324j),
173 (-0.5877838134765625 -0.80480599403381348j),
174 (-1.7554906861505515e-08 -0.99516552686691284j),
175 (0.58778399229049683 -0.80540722608566284j),
176 (0.95105582475662231 -0.30557557940483093j),
177 (0.95105588436126709 +0.31097668409347534j),
178 (0.5877838134765625 +0.81027895212173462j),
179 (2.3406542482007353e-08 +1.0000816583633423j),
180 (-0.5877840518951416 +0.80908381938934326j),
181 (-0.95105588436126709 +0.30904293060302734j),
182 (-0.95105588436126709 -0.30904296040534973j),
183 (-0.5877838134765625 -0.80908387899398804j),
184 (-2.6332360292258272e-08 -1.0000815391540527j),
185 (0.58778399229049683 -0.80908381938934326j),
186 (0.95105582475662231 -0.30904299020767212j),
187 (0.95105588436126709 +0.30904293060302734j),
188 (0.5877838134765625 +0.80908381938934326j),
189 (3.218399768911695e-08 +1.0000815391540527j))
196 src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,
197 sampling_freq * 0.10, 1.0)
198 head = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10))
199 dst2 = gr.vector_sink_c ()
203 taps = gr.firdes_hilbert (ntaps)
204 hd = gr.filter_delay_fc (taps)
206 fg.connect (src1, head)
207 fg.connect (head, (hd,0))
208 fg.connect (head, (hd,1))
213 result_data = dst2.data ()
215 self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5)
218 def test_003_filter_delay_two_inputs (self):
220 # give two different inputs
223 expected_result = ( -0.0020331963896751404j,
224 -0.0016448829555884004j,
225 -0.0032375147566199303j,
226 -0.0014826074475422502j,
227 -0.0033034090884029865j,
228 -0.00051144487224519253j,
229 -0.0043686260469257832j,
230 -0.0010198024101555347j,
231 -0.0082517862319946289j,
232 -0.003456643782556057j,
233 -0.014193611219525337j,
234 -0.005875137634575367j,
235 -0.020293503999710083j,
236 -0.0067503536120057106j,
237 -0.026798896491527557j,
238 -0.0073488112539052963j,
239 -0.037041611969470978j,
240 -0.010557252913713455j,
241 -0.055669989436864853j,
242 -0.018332764506340027j,
243 -0.089904911816120148j,
244 -0.033361352980136871j,
245 -0.16902604699134827j,
246 -0.074318811297416687j,
247 -0.58429563045501709j,
248 (7.2191945754696007e-09 -0.35892376303672791j),
249 (0.58778399229049683 +0.63660913705825806j),
250 (0.95105588436126709 +0.87681591510772705j),
251 (0.95105588436126709 +0.98705857992172241j),
252 (0.5877838134765625 +0.55447429418563843j),
253 (5.8516356205018383e-09 +0.026006083935499191j),
254 (-0.5877840518951416 -0.60616838932037354j),
255 (-0.95105588436126709 -0.9311758279800415j),
256 (-0.95105588436126709 -0.96169203519821167j),
257 (-0.5877838134765625 -0.57292771339416504j),
258 (-8.7774534307527574e-09 -0.0073488391935825348j),
259 (0.58778399229049683 +0.59720659255981445j),
260 (0.95105588436126709 +0.94438445568084717j),
261 (0.95105588436126709 +0.95582199096679688j),
262 (0.5877838134765625 +0.58196049928665161j),
263 (1.4629089051254596e-08 +0.0026587247848510742j),
264 (-0.5877840518951416 -0.59129220247268677j),
265 (-0.95105588436126709 -0.94841635227203369j),
266 (-0.95105588436126709 -0.95215457677841187j),
267 (-0.5877838134765625 -0.58535969257354736j),
268 (-1.7554906861505515e-08 -0.00051158666610717773j),
269 (0.58778399229049683 +0.58867418766021729j),
270 (0.95105582475662231 +0.94965213537216187j),
271 (0.95105588436126709 +0.95050644874572754j),
272 (0.5877838134765625 +0.58619076013565063j),
273 (2.3406542482007353e-08 +1.1920928955078125e-07j),
274 (-0.5877840518951416 -0.58783555030822754j),
275 (-0.95105588436126709 -0.95113480091094971j),
276 (-0.95105588436126709 -0.95113474130630493j),
277 (-0.5877838134765625 -0.58783555030822754j),
278 (-2.6332360292258272e-08 -8.1956386566162109e-08j),
279 (0.58778399229049683 +0.58783555030822754j),
280 (0.95105582475662231 +0.95113474130630493j),
281 (0.95105588436126709 +0.95113474130630493j),
282 (0.5877838134765625 +0.58783560991287231j),
283 (3.218399768911695e-08 +1.1920928955078125e-07j))
290 src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,sampling_freq * 0.10, 1.0)
291 src2 = gr.sig_source_f (sampling_freq, gr.GR_COS_WAVE,sampling_freq * 0.10, 1.0)
293 head1 = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10))
294 head2 = gr.head (gr.sizeof_float, int (ntaps + sampling_freq * 0.10))
296 taps = gr.firdes_hilbert (ntaps)
297 hd = gr.filter_delay_fc (taps)
299 dst2 = gr.vector_sink_c ()
301 fg.connect (src1, head1)
302 fg.connect (src2, head2)
304 fg.connect (head1, (hd,0))
305 fg.connect (head2, (hd,1))
306 fg.connect (hd, dst2)
311 result_data = dst2.data ()
313 self.assertComplexTuplesAlmostEqual (expected_result, result_data, 5)
316 if __name__ == '__main__':