Advertisement
Guest User

Untitled

a guest
May 28th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2014 <+YOU OR YOUR COMPANY+>.
  5. #
  6. # This 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, or (at your option)
  9. # any later version.
  10. #
  11. # This software 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. # along with this software; see the file COPYING. If not, write to
  18. # the Free Software Foundation, Inc., 51 Franklin Street,
  19. # Boston, MA 02110-1301, USA.
  20. #
  21.  
  22. from gnuradio import gr, gr_unittest
  23. from gnuradio import blocks
  24. import alamouti_swig as alamouti
  25. import sys,random
  26.  
  27. class qa_al_enc (gr_unittest.TestCase):
  28.  
  29. def setUp (self):
  30. self.tb = gr.top_block ()
  31.  
  32. def tearDown (self):
  33. self.tb = None
  34.  
  35. def test_001_t (self):
  36. # set up fg
  37.  
  38. n=2048
  39. lst1 = [random.randint(1, 10) for x in range (n)]
  40. lst2= [random.randint(1, 10) for x in range (n)]
  41.  
  42. numb=list()
  43. for i in range (n):
  44. numb.append(complex(lst1[i],lst2[i]))
  45.  
  46. def negconj(x):
  47. return -(x.conjugate())
  48. Tx1=list()
  49. Tx2=list()
  50. i=0
  51. while i<n:
  52. Tx1.append(numb[i])
  53. Tx1.append(negconj(numb[i+1]))
  54. Tx2.append(numb[i+1])
  55. Tx2.append(numb[i].conjugate())
  56. i+=2
  57.  
  58. expected_result1 = Tx1
  59. expected_result2 = Tx2
  60.  
  61. src = blocks.vector_source_c(numb)
  62. opr = alamouti.al_enc(n)
  63. dst1 = blocks.vector_sink_c()
  64. dst2 = blocks.vector_sink_c()
  65. self.tb.connect(src,opr)
  66. self.tb.connect((opr,0),dst1)
  67. self.tb.connect((opr,1),dst2)
  68. self.tb.run ()
  69. # check data
  70. #print "numb"
  71. #print numb
  72. #print "dst"
  73. #print dst1.data()
  74. #print dst2.data()
  75. result_data1 = dst1.data()
  76. result_data2 = dst2.data()
  77.  
  78. self.assertFloatTuplesAlmostEqual(expected_result1, result_data1)
  79. self.assertFloatTuplesAlmostEqual(expected_result2, result_data2)
  80.  
  81.  
  82.  
  83. if __name__ == '__main__':
  84. gr_unittest.run(qa_al_enc, "qa_al_enc.xml")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement