Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / python / gnuradio / gr / qa_pll_carriertracking.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_carriertracking (self):
35         expected_result = ((1.00000238419+6.47922693275e-09j),
36                            (0.998399555683+0.0565364062786j),
37                            (0.994261980057+0.10695001483j),
38                            (0.98843306303+0.151648163795j),
39                            (0.981579363346+0.191063538194j),
40                            (0.974212288857+0.225630432367j),
41                            (0.966734290123+0.255773901939j),
42                            (0.959442555904+0.281897842884j),
43                            (0.952551782131+0.304379671812j),
44                            (0.946205317974+0.323566257954j),
45                            (0.940503358841+0.339778244495j),
46                            (0.935505151749+0.353307723999j),
47                            (0.931235432625+0.364419162273j),
48                            (0.927616357803+0.373535633087j),
49                            (0.924710214138+0.380666583776j),
50                            (0.922494113445+0.386005342007j),
51                            (0.92093116045+0.389725029469j),
52                            (0.919974088669+0.391981720924j),
53                            (0.919572234154+0.392916500568j),
54                            (0.919680893421+0.392660915852j),
55                            (0.920248389244+0.39133310318j),
56                            (0.921222627163+0.389039844275j),
57                            (0.922548472881+0.385877460241j),
58                            (0.924184799194+0.381939411163j),
59                            (0.926086127758+0.377309292555j),
60                            (0.928135097027+0.37224984169j),
61                            (0.930293083191+0.366814315319j),
62                            (0.932614028454+0.360868781805j),
63                            (0.935064375401+0.354473829269j),
64                            (0.937613248825+0.347684770823j),
65                            (0.940225422382+0.340550601482j),
66                            (0.942881464958+0.33312189579j),
67                            (0.945559620857+0.325443327427j),
68                            (0.948240220547+0.31755694747j),
69                            (0.950899422169+0.309499144554j),
70                            (0.953524827957+0.301307469606j),
71                            (0.956105649471+0.293015599251j),
72                            (0.958630502224+0.284654557705j),
73                            (0.96103054285+0.276443749666j),
74                            (0.963361799717+0.26819768548j),
75                            (0.965623259544+0.259936869144j),
76                            (0.967810571194+0.251679092646j),
77                            (0.969916880131+0.243440493941j),
78                            (0.971936583519+0.235235646367j),
79                            (0.97387367487+0.227080151439j),
80                            (0.975726902485+0.218987599015j),
81                            (0.977494239807+0.210969462991j),
82                            (0.979169845581+0.203035995364j),
83                            (0.980761289597+0.195199295878j),
84                            (0.982269346714+0.187469303608j),
85                            (0.983659446239+0.180052131414j),
86                            (0.984931468964+0.1729388237j),
87                            (0.986136198044+0.165923252702j),
88                            (0.987275123596+0.159012272954j),
89                            (0.988349795341+0.15221118927j),
90                            (0.989354014397+0.145524248481j),
91                            (0.990296065807+0.138957872987j),
92                            (0.991178870201+0.132516458631j),
93                            (0.992005050182+0.126204773784j),
94                            (0.992770493031+0.120025672019j),
95                            (0.993480443954+0.113984130323j),
96                            (0.994139909744+0.108083210886j),
97                            (0.994751393795+0.102326385677j),
98                            (0.995293080807+0.0969148278236j),
99                            (0.995791256428+0.091630294919j),
100                            (0.996252119541+0.0864710733294j),
101                            (0.996678769588+0.0814334899187j),
102                            (0.997069239616+0.0765165910125j),
103                            (0.997423350811+0.071716658771j),
104                            (0.997748315334+0.0670333206654j),
105                            (0.998046517372+0.0624645166099j),
106                            (0.998317599297+0.058009263128j),
107                            (0.998557567596+0.053665690124j),
108                            (0.998775064945+0.0494344644248j),
109                            (0.998971700668+0.0453144386411j),
110                            (0.999140620232+0.0415064357221j),
111                            (0.99927687645+0.0379924885929j),
112                            (0.999400436878+0.0345549099147j),
113                            (0.999511957169+0.0311931278557j),
114                            (0.99961233139+0.0279070306569j),
115                            (0.999694347382+0.0246965941042j),
116                            (0.999765276909+0.0215622838587j),
117                            (0.999826848507+0.0185046810657j),
118                            (0.999880313873+0.0155246723443j),
119                            (0.999920129776+0.0126227736473j),
120                            (0.999949812889+0.00980060640723j),
121                            (0.99997317791+0.00705910893157j),
122                            (0.999990820885+0.00439921114594j),
123                            (0.999998450279+0.00202245195396j),
124                            (0.999998092651-0.00029227725463j),
125                            (0.999994516373-0.00254815118387j),
126                            (0.999988794327-0.00474932929501j),
127                            (0.999977111816-0.00689708162099j),
128                            (0.999957799911-0.00899503659457j),
129                            (0.999936699867-0.0110441967845j),
130                            (0.999914228916-0.0130464555696j),
131                            (0.999889075756-0.0150024276227j),
132                            (0.999855577946-0.0169130507857j),
133                            (0.999821305275-0.0187777336687j),
134                            (0.999786794186-0.0205969288945j))
135
136         sampling_freq = 10e3
137         freq = sampling_freq / 100
138
139         alpha = 0.1
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_carriertracking_cc(alpha, beta, maxf, minf)
146         head = gr.head (gr.sizeof_gr_complex, int (freq))
147         dst = gr.vector_sink_c ()
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         self.assertComplexTuplesAlmostEqual (expected_result, dst_data, 5)
156
157 if __name__ == '__main__':
158     gr_unittest.main ()