Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_pll_freqdet.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2004,2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
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)
10 # any later version.
11
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.
16
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.
21
22
23 from gnuradio import gr, gr_unittest
24 import math
25
26 class test_sig_source (gr_unittest.TestCase):
27
28     def setUp (self):
29         self.tb = gr.top_block()
30
31     def tearDown (self):
32         self.tb = None
33
34     def test_pll_refout (self):
35         expected_result = (1.1489677586e-07,
36                            0.972821060568,
37                            2.74556447638,
38                            5.14063078448,
39                            8.00965819311,
40                            11.2291393027,
41                            14.6967068752,
42                            18.3279143967,
43                            22.0534772463,
44                            25.8170093072,
45                            29.5729107661,
46                            33.284774699,
47                            36.923857393,
48                            40.4367950308,
49                            43.8452195091,
50                            47.1363835133,
51                            50.3011949468,
52                            53.3336447847,
53                            56.2301489564,
54                            58.9891659262,
55                            61.6107668417,
56                            64.0962975824,
57                            66.4481356707,
58                            68.6694531128,
59                            70.7640326003,
60                            72.7048735417,
61                            74.5033180826,
62                            76.2012544926,
63                            77.8019199967,
64                            79.3088126954,
65                            80.7255907715,
66                            82.0560369166,
67                            83.3039516093,
68                            84.47312347,
69                            85.5673411194,
70                            86.5902864563,
71                            87.5456117346,
72                            88.4368565575,
73                            89.2363918613,
74                            89.9860999864,
75                            90.688880206,
76                            91.3474598523,
77                            91.9644654653,
78                            92.5423042123,
79                            93.0832706099,
80                            93.5894872344,
81                            94.0629225081,
82                            94.5054203452,
83                            94.9186882929,
84                            95.3043331057,
85                            95.6326268597,
86                            95.9117515522,
87                            96.1801447842,
88                            96.437391527,
89                            96.6831953314,
90                            96.9173605408,
91                            97.1397982206,
92                            97.3504727968,
93                            97.5493842694,
94                            97.7366275022,
95                            97.9123092169,
96                            98.0766013539,
97                            98.2297054988,
98                            98.3408087235,
99                            98.448722155,
100                            98.5534457933,
101                            98.6549322065,
102                            98.7531932527,
103                            98.8481459259,
104                            98.9397487233,
105                            99.0279067813,
106                            99.1125074491,
107                            99.193438076,
108                            99.2705800823,
109                            99.3438030304,
110                            99.3817663128,
111                            99.3911400359,
112                            99.4089388448,
113                            99.4334136894,
114                            99.4630408207,
115                            99.4964684305,
116                            99.5325166512,
117                            99.5701538394,
118                            99.6084432158,
119                            99.6466021546,
120                            99.6839073198,
121                            99.7197895289,
122                            99.7537270313,
123                            99.7542606398,
124                            99.7595848672,
125                            99.7691186729,
126                            99.7822928746,
127                            99.7986331535,
128                            99.8175940432,
129                            99.838713083,
130                            99.8614922382,
131                            99.8854571901,
132                            99.9101454781,
133                            99.9351302152,
134                            99.9599845147)
135
136         sampling_freq = 10e3
137         freq = sampling_freq / 100
138
139         alpha = 0.2
140         beta = alpha * alpha / 4.0
141         maxf = 1
142         minf = -1
143
144         src = gr.sig_source_c (sampling_freq, gr.GR_COS_WAVE, freq, 1.0)
145         pll = gr.pll_freqdet_cf(alpha, beta, maxf, minf)
146         head = gr.head (gr.sizeof_float, int (freq))
147         dst = gr.vector_sink_f ()
148
149         self.tb.connect (src, pll, head)
150         self.tb.connect (head, dst)
151
152         self.tb.run ()
153         dst_data = dst.data ()
154
155         # convert it from normalized frequency to absolute frequency (Hz)
156         dst_data = [i*(sampling_freq/(2*math.pi)) for i in dst_data]
157
158         self.assertFloatTuplesAlmostEqual (expected_result, dst_data, 3)
159
160 if __name__ == '__main__':
161     gr_unittest.main ()