3 # Copyright 2004,2007,2010 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 3, 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
28 class test_agc (gr_unittest.TestCase):
31 self.tb = gr.top_block ()
38 ''' Test the complex AGC loop (single rate input) '''
42 (100.000244140625+7.2191943445432116e-07j),
43 (72.892257690429688+52.959323883056641j),
44 (25.089065551757812+77.216217041015625j),
45 (-22.611061096191406+69.589706420898438j),
46 (-53.357715606689453+38.766635894775391j),
47 (-59.458671569824219+3.4792964243024471e-07j),
48 (-43.373462677001953-31.512666702270508j),
49 (-14.94139289855957-45.984889984130859j),
50 (13.478158950805664-41.48150634765625j),
51 (31.838506698608398-23.132022857666016j),
52 (35.519271850585938-3.1176801940091536e-07j),
53 (25.942903518676758+18.848621368408203j),
54 (8.9492912292480469+27.5430908203125j),
55 (-8.0852642059326172+24.883890151977539j),
56 (-19.131628036499023+13.899936676025391j),
57 (-21.383295059204102+3.1281737733479531e-07j),
58 (-15.650330543518066-11.370632171630859j),
59 (-5.4110145568847656-16.65339469909668j),
60 (4.9008159637451172-15.083160400390625j),
61 (11.628337860107422-8.4484796524047852j),
62 (13.036135673522949-2.288476110834381e-07j),
63 (9.5726661682128906+6.954948902130127j),
64 (3.3216962814331055+10.223132133483887j),
65 (-3.0204284191131592+9.2959251403808594j),
66 (-7.1977195739746094+5.2294478416442871j),
67 (-8.1072216033935547+1.8976157889483147e-07j),
68 (-5.9838657379150391-4.3475332260131836j),
69 (-2.0879747867584229-6.4261269569396973j),
70 (1.9100792407989502-5.8786196708679199j),
71 (4.5814824104309082-3.3286411762237549j),
72 (5.1967458724975586-1.3684227440080576e-07j),
73 (3.8647139072418213+2.8078789710998535j),
74 (1.3594740629196167+4.1840314865112305j),
75 (-1.2544282674789429+3.8607344627380371j),
76 (-3.0366206169128418+2.2062335014343262j),
77 (-3.4781389236450195+1.1194014604143376e-07j),
78 (-2.6133756637573242-1.8987287282943726j),
79 (-0.9293016791343689-2.8600969314575195j),
80 (0.86727333068847656-2.6691930294036865j),
81 (2.1243946552276611-1.5434627532958984j),
82 (2.4633183479309082-8.6486437567145913e-08j),
83 (1.8744727373123169+1.3618841171264648j),
84 (0.67528903484344482+2.0783262252807617j),
85 (-0.63866174221038818+1.965599536895752j),
86 (-1.5857341289520264+1.152103066444397j),
87 (-1.8640764951705933+7.6355092915036948e-08j),
88 (-1.4381576776504517-1.0448826551437378j),
89 (-0.52529704570770264-1.6166983842849731j),
90 (0.50366902351379395-1.5501341819763184j),
91 (1.26766037940979-0.92100900411605835j))
94 src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE,
95 sampling_freq * 0.10, 100.0)
96 dst1 = gr.vector_sink_c ()
97 head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10))
99 agc = gr.agc_cc(1e-3, 1, 1, 1000)
101 tb.connect (src1, head)
102 tb.connect (head, agc)
103 tb.connect (agc, dst1)
105 if test_output == True:
106 tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc_cc.dat"))
109 dst_data = dst1.data ()
110 self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4)
113 ''' Test the floating point AGC loop (single rate input) '''
117 7.2191943445432116e-07,
122 4.269894304798072e-07,
127 -4.683740257860336e-07,
132 5.7254135299444897e-07,
137 -5.0591745548445033e-07,
142 4.9936483037527069e-07,
147 -4.188150626305287e-07,
152 3.8512698097292741e-07,
157 -3.1982864356905338e-07,
162 2.882407841298118e-07,
169 src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,
170 sampling_freq * 0.10, 100.0)
171 dst1 = gr.vector_sink_f ()
172 head = gr.head (gr.sizeof_float, int (5*sampling_freq * 0.10))
174 agc = gr.agc_ff(1e-3, 1, 1, 1000)
176 tb.connect (src1, head)
177 tb.connect (head, agc)
178 tb.connect (agc, dst1)
180 if test_output == True:
181 tb.connect (agc, gr.file_sink(gr.sizeof_float, "test_agc_ff.dat"))
184 dst_data = dst1.data ()
185 self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4)
188 ''' Test the complex AGC loop (attack and decay rate inputs) '''
192 ((100.000244140625+7.2191943445432116e-07j),
193 (0.80881959199905396+0.58764183521270752j),
194 (0.30894950032234192+0.95084899663925171j),
195 (-0.30895623564720154+0.95086973905563354j),
196 (-0.80887287855148315+0.58768033981323242j),
197 (-0.99984413385391235+5.850709250410091e-09j),
198 (-0.80889981985092163-0.58770018815994263j),
199 (-0.30897706747055054-0.95093393325805664j),
200 (0.30898112058639526-0.95094609260559082j),
201 (0.80893135070800781-0.58772283792495728j),
202 (0.99990922212600708-8.7766354184282136e-09j),
203 (0.80894720554351807+0.58773452043533325j),
204 (0.30899339914321899+0.95098406076431274j),
205 (-0.30899572372436523+0.95099133253097534j),
206 (-0.80896598100662231+0.58774799108505249j),
207 (-0.99994778633117676+1.4628290578855285e-08j),
208 (-0.80897533893585205-0.58775502443313599j),
209 (-0.30900305509567261-0.95101380348205566j),
210 (0.30900448560714722-0.95101797580718994j),
211 (0.80898630619049072-0.58776277303695679j),
212 (0.99997037649154663-1.7554345532744264e-08j),
213 (0.80899184942245483+0.58776694536209106j),
214 (0.30900871753692627+0.95103120803833008j),
215 (-0.30900952219963074+0.95103377103805542j),
216 (-0.8089984655380249+0.58777159452438354j),
217 (-0.99998390674591064+2.3406109050938539e-08j),
218 (-0.809001624584198-0.58777409791946411j),
219 (-0.30901208519935608-0.95104163885116577j),
220 (0.30901262164115906-0.95104306936264038j),
221 (0.80900543928146362-0.587776780128479j),
222 (0.99999171495437622-2.6332081404234486e-08j),
223 (0.80900734663009644+0.58777821063995361j),
224 (0.30901408195495605+0.95104765892028809j),
225 (-0.30901429057121277+0.95104855298995972j),
226 (-0.80900967121124268+0.58777981996536255j),
227 (-0.99999648332595825+3.2183805842578295e-08j),
228 (-0.80901080369949341-0.58778077363967896j),
229 (-0.30901527404785156-0.95105135440826416j),
230 (0.30901545286178589-0.95105189085006714j),
231 (0.80901217460632324-0.58778166770935059j),
232 (0.99999916553497314-3.5109700036173308e-08j),
233 (0.809012770652771+0.58778214454650879j),
234 (0.30901595950126648+0.9510534405708313j),
235 (-0.30901598930358887+0.95105385780334473j),
236 (-0.80901366472244263+0.58778274059295654j),
237 (-1.0000008344650269+4.0961388947380328e-08j),
238 (-0.8090139627456665-0.58778303861618042j),
239 (-0.30901634693145752-0.95105475187301636j),
240 (0.30901640653610229-0.95105493068695068j),
241 (0.80901449918746948-0.5877833366394043j))
244 src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE,
245 sampling_freq * 0.10, 100)
246 dst1 = gr.vector_sink_c ()
247 head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10))
249 agc = gr.agc2_cc(1e-2, 1e-3, 1, 1, 1000)
251 tb.connect (src1, head)
252 tb.connect (head, agc)
253 tb.connect (agc, dst1)
255 if test_output == True:
256 tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc2_cc.dat"))
259 dst_data = dst1.data ()
260 self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4)
263 ''' Test the floating point AGC loop (attack and decay rate inputs) '''
267 (7.2191943445432116e-07,
272 8.6260438791896377e-09,
276 -0.61939650774002075,
277 -1.2590258613442984e-08,
282 2.0983527804219193e-08,
286 -0.61937344074249268,
287 -2.5180233009791664e-08,
292 3.3573645197293445e-08,
296 -0.61937350034713745,
297 -3.7770352179222755e-08,
302 4.6163762590367696e-08,
306 -0.61937344074249268,
307 -5.0360466019583328e-08,
312 5.8753879983441948e-08,
316 -0.61937344074249268)
319 src1 = gr.sig_source_f (sampling_freq, gr.GR_SIN_WAVE,
320 sampling_freq * 0.10, 100)
321 dst1 = gr.vector_sink_f ()
322 head = gr.head (gr.sizeof_float, int (5*sampling_freq * 0.10))
324 agc = gr.agc2_ff(1e-2, 1e-3, 1, 1, 1000)
326 tb.connect (src1, head)
327 tb.connect (head, agc)
328 tb.connect (agc, dst1)
330 if test_output == True:
331 tb.connect (agc, gr.file_sink(gr.sizeof_float, "test_agc2_ff.dat"))
334 dst_data = dst1.data ()
335 self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 4)
339 ''' Test the complex AGC loop (attack and decay rate inputs) '''
343 ((100.000244140625+7.2191943445432116e-07j),
344 (0.80881959199905396+0.58764183521270752j),
345 (0.30894950032234192+0.95084899663925171j),
346 (-0.30895623564720154+0.95086973905563354j),
347 (-0.80887287855148315+0.58768033981323242j),
348 (-0.99984413385391235+5.850709250410091e-09j),
349 (-0.80889981985092163-0.58770018815994263j),
350 (-0.30897706747055054-0.95093393325805664j),
351 (0.30898112058639526-0.95094609260559082j),
352 (0.80893135070800781-0.58772283792495728j),
353 (0.99990922212600708-8.7766354184282136e-09j),
354 (0.80894720554351807+0.58773452043533325j),
355 (0.30899339914321899+0.95098406076431274j),
356 (-0.30899572372436523+0.95099133253097534j),
357 (-0.80896598100662231+0.58774799108505249j),
358 (-0.99994778633117676+1.4628290578855285e-08j),
359 (-0.80897533893585205-0.58775502443313599j),
360 (-0.30900305509567261-0.95101380348205566j),
361 (0.30900448560714722-0.95101797580718994j),
362 (0.80898630619049072-0.58776277303695679j),
363 (0.99997037649154663-1.7554345532744264e-08j),
364 (0.80899184942245483+0.58776694536209106j),
365 (0.30900871753692627+0.95103120803833008j),
366 (-0.30900952219963074+0.95103377103805542j),
367 (-0.8089984655380249+0.58777159452438354j),
368 (-0.99998390674591064+2.3406109050938539e-08j),
369 (-0.809001624584198-0.58777409791946411j),
370 (-0.30901208519935608-0.95104163885116577j),
371 (0.30901262164115906-0.95104306936264038j),
372 (0.80900543928146362-0.587776780128479j),
373 (0.99999171495437622-2.6332081404234486e-08j),
374 (0.80900734663009644+0.58777821063995361j),
375 (0.30901408195495605+0.95104765892028809j),
376 (-0.30901429057121277+0.95104855298995972j),
377 (-0.80900967121124268+0.58777981996536255j),
378 (-0.99999648332595825+3.2183805842578295e-08j),
379 (-0.80901080369949341-0.58778077363967896j),
380 (-0.30901527404785156-0.95105135440826416j),
381 (0.30901545286178589-0.95105189085006714j),
382 (0.80901217460632324-0.58778166770935059j),
383 (0.99999916553497314-3.5109700036173308e-08j),
384 (0.809012770652771+0.58778214454650879j),
385 (0.30901595950126648+0.9510534405708313j),
386 (-0.30901598930358887+0.95105385780334473j),
387 (-0.80901366472244263+0.58778274059295654j),
388 (-1.0000008344650269+4.0961388947380328e-08j),
389 (-0.8090139627456665-0.58778303861618042j),
390 (-0.30901634693145752-0.95105475187301636j),
391 (0.30901640653610229-0.95105493068695068j),
392 (0.80901449918746948-0.5877833366394043j))
395 src1 = gr.sig_source_c (sampling_freq, gr.GR_SIN_WAVE,
396 sampling_freq * 0.10, 100)
397 dst1 = gr.vector_sink_c ()
398 head = gr.head (gr.sizeof_gr_complex, int (5*sampling_freq * 0.10))
400 agc = gr.agc2_cc(1e-2, 1e-3, 1, 1, 1000)
402 tb.connect (src1, head)
403 tb.connect (head, agc)
404 tb.connect (agc, dst1)
406 if test_output == True:
407 tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_agc2_cc.dat"))
410 dst_data = dst1.data ()
411 self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4)
414 def test_100(self): # FIXME needs work
415 ''' Test complex feedforward agc with constant input '''
416 input_data = 16*(0.0,) + 64*(1.0,) + 64*(0.0,)
419 src = gr.vector_source_c(input_data)
420 agc = gr.feedforward_agc_cc(16, 2.0)
421 dst = gr.vector_sink_c ()
422 self.tb.connect (src, agc, dst)
424 if test_output == True:
425 self.tb.connect (agc, gr.file_sink(gr.sizeof_gr_complex, "test_feedforward_cc.dat"))
428 dst_data = dst.data ()
429 #self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 4)
432 if __name__ == '__main__':
433 gr_unittest.run(test_agc, "test_agc.xml")