Exemple #1
0
 def testToneCreate(self):
     """create a Dds with a DdsTone instance"""
     self.assertIsInstance(self.dev, iio.Device, 'ok')
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     self.assertIsInstance(tone, pluto_dds.DdsTone,
                           'ddsTone instance created')
     tone.setFreq(1)
     npt.assert_almost_equal(tone.getFreq(),
                             1.0,
                             decimal=4,
                             err_msg='initial frequency value')
     tone.setPhase(0)
     npt.assert_almost_equal(tone.getPhase(),
                             0.0,
                             decimal=4,
                             err_msg='initial phase value')
     npt.assert_almost_equal(tone.getPhase('Q'),
                             270.0,
                             decimal=4,
                             err_msg='initial phase value')
     tone.setAmplitude(0.5)
     npt.assert_almost_equal(tone.getAmplitude(),
                             0.5,
                             decimal=4,
                             err_msg='initial amplitude value')
Exemple #2
0
 def testSetPhase(self):
     """confirm the relative I/Q phases for +/- frequencies"""
     dds = pluto_dds.Dds(self.dev)
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     tone.frequency = 1
     tone.phase = 180  # set phase mid way
     i_phase = tone.getPhase()
     q_phase = tone.getPhase('Q')
Exemple #3
0
 def testPhaseNormalisation(self):
     """confirm phase values restricted to 0 <= phi <= 360"""
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     tone.phase = -10
     npt.assert_almost_equal(tone.phase,
                             350,
                             decimal=2,
                             err_msg='phase norm -10 -> 350 degs')
Exemple #4
0
 def testWithinFs(self):
     """confirm freq values are within +/- half fs"""
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     tone.amplitude = 0.5
     tone.frequency = 0.5
     fs = tone.getSamplingFreq() 
     with self.assertRaises(ValueError,
             msg='when setting f outside +/-fs/2'):  
         tone.setFreq(fs)
Exemple #5
0
 def testPosNegFreq(self):
     """confirm the relative I/Q phases for +/- frequencies"""
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     fs = tone.getSamplingFreq()        
     tone.frequency = fs/8
     tone.phase = 180       # set phase mid way
     i_phase = tone.getPhase()
     q_phase = tone.getPhase('Q')
     tone.frequency = -fs/4
     self.assertEqual(i_phase, tone.getPhase(),
                      'I phase equal for +/- freq')
     self.assertEqual(abs(q_phase - tone.getPhase('Q')), 180,
                      'Q phase opposite for +/- freq')
Exemple #6
0
 def testOnOff(self):
     """confirm amplitude settings are preserved from off to on"""
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     tone.amplitude = 0.5   # some initial setting
     self.assertEqual(tone.amplitude, 0.5, "setting attribute ok")
     tone.i_ch.attrs['raw'].value = '0'
     self.assertEqual(tone.amplitude, 0.5, "off preserves amplitude")
     tone.i_ch.attrs['raw'].value = '1'
     self.assertEqual(tone.amplitude, 0.5, "return to previous setting")
     tone.i_ch.attrs['raw'].value = '0'
     tone.amplitude = 0.1
     tone.i_ch.attrs['raw'].value = '1'
     npt.assert_almost_equal(tone.amplitude, 0.1, decimal=4,
                             err_msg="ok setting change even when off")
Exemple #7
0
 def testOnOff(self):
     """confirm amplitude settings are preserved from off to on"""
     tone = pluto_dds.DdsTone(self.dev, 'F1')
     tone.amplitude = 0.5  # some initial setting
     self.assertEqual(tone.amplitude, 0.5, "setting attribute ok")
     tone.state(OFF)
     self.assertEqual(tone.amplitude, 0.0, "off make amplitude 0")
     tone.state(ON)
     self.assertEqual(tone.amplitude, 0.5, "return to previous setting")
     tone.state(OFF)
     tone.amplitude = 0.1
     tone.state(ON)
     npt.assert_almost_equal(tone.amplitude,
                             0.1,
                             decimal=4,
                             err_msg="ok setting change even when off")
Exemple #8
0
    def testProperties(self):
        """confirm read and write to properties"""
        tone = pluto_dds.DdsTone(self.dev, 'F1')
        fs = tone.getSamplingFreq()        
        tone.frequency = -fs/4
        npt.assert_almost_equal(tone.frequency, -fs/4, decimal=3,
                         err_msg='using frequency property')
        tone.phase = 20
        npt.assert_almost_equal(tone.phase, 20.0, decimal=3,
                         err_msg='using phase property')
        tone.amplitude = 0.2
        npt.assert_almost_equal(tone.amplitude, 0.2, decimal=3,
                         err_msg='using amplitude property')
        with self.assertRaises(ValueError,

                    msg='value set out of 0 .. 1 range'):
            tone.amplitude = 10