コード例 #1
0
 def setUp(self):
     # Number of channels
     self.M = 4
     self.logM = int(math.log(self.M) / math.log(2))
     # The amount of data to send
     self.n_data = self.M * 30  #200
     # Baseband sampling rate
     self.fs = 1000
     # Input samp rate to channelizer
     self.ifs = self.M * self.fs
     # Each channel contains a pure frequency with an offset and
     # amplitude.
     self.freqs = [0, 100, 200, -300]
     self.amplitudes = [1, 1, -0.2, 0.5]
     # Random number generator
     rg = random.Random(0)
     self.myrand = rg.random
     self.myrandint = rg.randint
     # Width of a complex number
     self.width = 32
     # Generate some taps
     self.taps, self.tapscale = get_channelizer_taps(self.M, n_taps=100)
     # How often to send input.
     # For large FFTs this must be larger since the speed scales as MlogM.
     # Otherwise we get an overflow error.
     self.sendnth = 8
     # Get the input data
     self.data = get_mixed_sinusoids(self.fs, self.n_data, self.freqs,
                                     self.amplitudes)
     # Scale the input data to remain in (-1 to 1)
     datamax = 0
     for d in self.data:
         datamax = max(datamax, abs(d.real), abs(d.imag))
     self.inputscale = datamax
     self.data = [d / datamax for d in self.data]
     # Send in some meta data
     self.mwidth = 3
     self.ms = [self.myrandint(0, 7) for d in self.data]
     # Create the test bench
     name = 'complex'
     defines = config.updated_defines({
         "DEBUG": False,
         "WIDTH": self.width,
         "MWIDTH": self.mwidth
     })
     rtaps = []
     for tt in self.taps:
         rtaps.append(list(reversed(tt)))
     self.tb = ChannelizerTestBenchIcarus(name, self.M, rtaps, self.data,
                                          self.sendnth, self.ms, defines)
     self.ftb = FilterbankTestBenchIcarus(name, self.M, len(self.taps[0]),
                                          self.taps, self.data,
                                          self.sendnth, self.ms, defines)
     self.ftb.prepare()
     self.tb.prepare()
コード例 #2
0
 def setUp(self):
     # Number of channels
     self.M = 4
     self.logM = int(math.log(self.M)/math.log(2))
     # The amount of data to send
     self.n_data = self.M * 30#200
     # Baseband sampling rate
     self.fs = 1000        
     # Input samp rate to channelizer
     self.ifs = self.M*self.fs       
     # Each channel contains a pure frequency with an offset and
     # amplitude.
     self.freqs = [0, 100, 200, -300]
     self.amplitudes = [1, 1, -0.2, 0.5]
     # Random number generator
     rg = random.Random(0)
     self.myrand = rg.random
     self.myrandint = rg.randint
     # Width of a complex number
     self.width = 32
     # Generate some taps
     self.taps, self.tapscale = get_channelizer_taps(self.M, n_taps=100)
     # How often to send input.
     # For large FFTs this must be larger since the speed scales as MlogM.
     # Otherwise we get an overflow error.
     self.sendnth = 8
     # Get the input data
     self.data = get_mixed_sinusoids(self.fs, self.n_data, self.freqs, self.amplitudes)
     # Scale the input data to remain in (-1 to 1)
     datamax = 0
     for d in self.data:
         datamax = max(datamax, abs(d.real), abs(d.imag))
     self.inputscale = datamax
     self.data = [d/datamax for d in self.data]
     # Send in some meta data
     self.mwidth = 3
     self.ms = [self.myrandint(0, 7) for d in self.data]
     # Create the test bench
     name = 'complex'
     defines = config.updated_defines({"DEBUG": False,
                                       "WIDTH": self.width,
                                       "MWIDTH": self.mwidth})
     rtaps = []
     for tt in self.taps:
         rtaps.append(list(reversed(tt)))
     self.tb = ChannelizerTestBenchIcarus(name, self.M, rtaps, self.data,
                                          self.sendnth, self.ms, defines)
     self.ftb = FilterbankTestBenchIcarus(name, self.M, len(self.taps[0]), self.taps, self.data,
                                          self.sendnth, self.ms, defines)
     self.ftb.prepare()
     self.tb.prepare()
コード例 #3
0
class TestChannelizer(unittest.TestCase):
    """
    Test the verilog channelizer.
    """
    def setUp(self):
        # Number of channels
        self.M = 4
        self.logM = int(math.log(self.M) / math.log(2))
        # The amount of data to send
        self.n_data = self.M * 30  #200
        # Baseband sampling rate
        self.fs = 1000
        # Input samp rate to channelizer
        self.ifs = self.M * self.fs
        # Each channel contains a pure frequency with an offset and
        # amplitude.
        self.freqs = [0, 100, 200, -300]
        self.amplitudes = [1, 1, -0.2, 0.5]
        # Random number generator
        rg = random.Random(0)
        self.myrand = rg.random
        self.myrandint = rg.randint
        # Width of a complex number
        self.width = 32
        # Generate some taps
        self.taps, self.tapscale = get_channelizer_taps(self.M, n_taps=100)
        # How often to send input.
        # For large FFTs this must be larger since the speed scales as MlogM.
        # Otherwise we get an overflow error.
        self.sendnth = 8
        # Get the input data
        self.data = get_mixed_sinusoids(self.fs, self.n_data, self.freqs,
                                        self.amplitudes)
        # Scale the input data to remain in (-1 to 1)
        datamax = 0
        for d in self.data:
            datamax = max(datamax, abs(d.real), abs(d.imag))
        self.inputscale = datamax
        self.data = [d / datamax for d in self.data]
        # Send in some meta data
        self.mwidth = 3
        self.ms = [self.myrandint(0, 7) for d in self.data]
        # Create the test bench
        name = 'complex'
        defines = config.updated_defines({
            "DEBUG": False,
            "WIDTH": self.width,
            "MWIDTH": self.mwidth
        })
        rtaps = []
        for tt in self.taps:
            rtaps.append(list(reversed(tt)))
        self.tb = ChannelizerTestBenchIcarus(name, self.M, rtaps, self.data,
                                             self.sendnth, self.ms, defines)
        self.ftb = FilterbankTestBenchIcarus(name, self.M, len(self.taps[0]),
                                             self.taps, self.data,
                                             self.sendnth, self.ms, defines)
        self.ftb.prepare()
        self.tb.prepare()

    def tearDown(self):
        pass

    def test_channelizer(self):
        """
        Test a channelizer.
        """
        steps_rqd = self.n_data * self.sendnth + 1000
        self.tb.run(steps_rqd)
        p_convolved, p_final = pychannelizer(self.taps, self.data, self.M)
        received = [x * self.M for x in self.tb.out_samples]
        skip = (len(self.taps[0]) - 1) * self.M
        received = [received[i + skip::self.M] for i in range(self.M)]
        expected = get_expected_channelized_data(self.fs, self.n_data / self.M,
                                                 self.freqs, self.amplitudes)
        for ed, dd, pd in zip(expected, received, p_final):
            pd = [p * self.tapscale * self.inputscale for p in pd]
            dd = [d * self.tapscale * self.inputscale for d in dd]
            epf = ed[-1] / pd[-1]
            rpd = [p * epf for p in pd]
            self.assertTrue(len(rpd) != 0)
            self.assertTrue(len(ed) != 0)
            self.assertTrue(len(pd) != 0)
            allowed_dev = 5e-4
            for e, p in zip(ed, rpd):
                dev = abs(e - p)
                self.assertTrue(dev < allowed_dev)
            allowed_dev = 5e-3
            for d, p in zip(dd, pd):
                dev = abs(d - p)
                self.assertTrue(dev < allowed_dev)
        # Compare ms
        self.assertEqual(len(self.tb.out_ms), len(self.ms))
        for r, e in zip(self.tb.out_ms, self.ms):
            self.assertEqual(r, e)
        # Compare first_channel signals
        fcs = ([1] + [0] * (self.M - 1)) * (self.n_data / self.M)
        self.assertEqual(len(self.tb.out_fc), len(fcs))
        for r, e in zip(self.tb.out_fc, fcs):
            self.assertEqual(r, e)
コード例 #4
0
class TestChannelizer(unittest.TestCase):
    """
    Test the verilog channelizer.
    """

    def setUp(self):
        # Number of channels
        self.M = 4
        self.logM = int(math.log(self.M)/math.log(2))
        # The amount of data to send
        self.n_data = self.M * 30#200
        # Baseband sampling rate
        self.fs = 1000        
        # Input samp rate to channelizer
        self.ifs = self.M*self.fs       
        # Each channel contains a pure frequency with an offset and
        # amplitude.
        self.freqs = [0, 100, 200, -300]
        self.amplitudes = [1, 1, -0.2, 0.5]
        # Random number generator
        rg = random.Random(0)
        self.myrand = rg.random
        self.myrandint = rg.randint
        # Width of a complex number
        self.width = 32
        # Generate some taps
        self.taps, self.tapscale = get_channelizer_taps(self.M, n_taps=100)
        # How often to send input.
        # For large FFTs this must be larger since the speed scales as MlogM.
        # Otherwise we get an overflow error.
        self.sendnth = 8
        # Get the input data
        self.data = get_mixed_sinusoids(self.fs, self.n_data, self.freqs, self.amplitudes)
        # Scale the input data to remain in (-1 to 1)
        datamax = 0
        for d in self.data:
            datamax = max(datamax, abs(d.real), abs(d.imag))
        self.inputscale = datamax
        self.data = [d/datamax for d in self.data]
        # Send in some meta data
        self.mwidth = 3
        self.ms = [self.myrandint(0, 7) for d in self.data]
        # Create the test bench
        name = 'complex'
        defines = config.updated_defines({"DEBUG": False,
                                          "WIDTH": self.width,
                                          "MWIDTH": self.mwidth})
        rtaps = []
        for tt in self.taps:
            rtaps.append(list(reversed(tt)))
        self.tb = ChannelizerTestBenchIcarus(name, self.M, rtaps, self.data,
                                             self.sendnth, self.ms, defines)
        self.ftb = FilterbankTestBenchIcarus(name, self.M, len(self.taps[0]), self.taps, self.data,
                                             self.sendnth, self.ms, defines)
        self.ftb.prepare()
        self.tb.prepare()

    def tearDown(self):
        pass

    def test_channelizer(self):
        """
        Test a channelizer.
        """
        steps_rqd = self.n_data * self.sendnth + 1000
        self.tb.run(steps_rqd)
        p_convolved, p_final = pychannelizer(self.taps, self.data, self.M)
        received = [x*self.M for x in self.tb.out_samples]
        skip = (len(self.taps[0])-1)*self.M
        received = [received[i+skip::self.M] for i in range(self.M)]
        expected = get_expected_channelized_data(
            self.fs, self.n_data/self.M, self.freqs, self.amplitudes)
        for ed, dd, pd in zip(expected, received, p_final):
            pd = [p*self.tapscale*self.inputscale for p in pd]
            dd = [d*self.tapscale*self.inputscale for d in dd]
            epf = ed[-1]/pd[-1]
            rpd = [p*epf for p in pd]
            self.assertTrue(len(rpd) != 0)
            self.assertTrue(len(ed) != 0)
            self.assertTrue(len(pd) != 0)
            allowed_dev = 5e-4
            for e, p in zip(ed, rpd):
                dev = abs(e-p)
                self.assertTrue(dev < allowed_dev)
            allowed_dev = 5e-3
            for d, p in zip(dd, pd):
                dev = abs(d-p)
                self.assertTrue(dev < allowed_dev)
        # Compare ms
        self.assertEqual(len(self.tb.out_ms), len(self.ms))
        for r, e in zip(self.tb.out_ms, self.ms):
            self.assertEqual(r, e)
        # Compare first_channel signals
        fcs = ([1] + [0]*(self.M-1)) * (self.n_data/self.M)
        self.assertEqual(len(self.tb.out_fc), len(fcs))
        for r, e in zip(self.tb.out_fc, fcs):
            self.assertEqual(r, e)