Exemple #1
0
    def applyAmplitude(self, signal, userTimeAll_s, noiseParams):
        '''
    Applies amplitude modulation to signal.

    This method applies polynomial modulation.

    Parameters
    ----------
    signal : numpy.ndarray
      Signal sample vector. Each element defines signal amplitude in range
      [-1; +1]. This vector is modified in place.
    userTimeAll_s : numpy.ndarray
      Sample time vector. Each element defines sample time in seconds.
    noiseParams : NoiseParameters
      Noise parameters to adjust signal amplitude level.

    Returns
    -------
    numpy.ndarray
      Array with output samples
    '''

        poly = self.poly
        if poly is not None:
            amplitudeVector = poly(userTimeAll_s)
            amplitudeVector = AmplitudeBase.convertUnits2Amp(
                amplitudeVector, self.units, noiseParams)
            signal *= amplitudeVector
        else:
            amplitude = AmplitudeBase.convertUnits2Amp(1., self.units,
                                                       noiseParams)
            signal *= amplitude

        return signal
def test_AmplitudeBase_units():
  '''
  Generic tests for AmplitudeBase methods
  '''
  ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR)
  assert AmplitudeBase.UNITS_SNR == ampl.getUnits()
  ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR_DB)
  assert AmplitudeBase.UNITS_SNR_DB == ampl.getUnits()
def test_AmplitudeBase_convertSNR():
    '''
  Generic tests for AmplitudeBase conversion to volts
  '''
    noiseParams = NoiseParameters(1e6, 1.)
    assert 10. * numpy.log10(4.) == AmplitudeBase.convertUnits2SNR(
        4., AmplitudeBase.UNITS_AMPLITUDE, noiseParams)
    assert 10. * numpy.log10(1.) == AmplitudeBase.convertUnits2SNR(
        4., AmplitudeBase.UNITS_POWER, noiseParams)
    assert 20. == AmplitudeBase.convertUnits2SNR(100, AmplitudeBase.UNITS_SNR,
                                                 noiseParams)
    assert 15. == AmplitudeBase.convertUnits2SNR(15.,
                                                 AmplitudeBase.UNITS_SNR_DB,
                                                 noiseParams)
def test_AmplitudeBase_convertVolts():
    '''
  Generic tests for AmplitudeBase conversion to volts
  '''
    noiseParams = NoiseParameters(1e6, 1.)
    assert 4. == AmplitudeBase.convertUnits2Amp(4.,
                                                AmplitudeBase.UNITS_AMPLITUDE,
                                                noiseParams)
    assert 2. == AmplitudeBase.convertUnits2Amp(4., AmplitudeBase.UNITS_POWER,
                                                noiseParams)
    assert 20. == AmplitudeBase.convertUnits2Amp(100, AmplitudeBase.UNITS_SNR,
                                                 noiseParams)
    assert 2. == AmplitudeBase.convertUnits2Amp(0., AmplitudeBase.UNITS_SNR_DB,
                                                noiseParams)
Exemple #5
0
  def applyAmplitude(self, signal, userTimeAll_s, noiseParams):
    '''
    Applies amplitude modulation to signal.

    Parameters
    ----------
    signal : numpy.ndarray
      Signal sample vector. Each element defines signal amplitude in range
      [-1; +1]. This vector is modified in place.
    userTimeAll_s : numpy.ndarray
      Sample time vector. Each element defines sample time in seconds.
    noiseParams : NoiseParameters
      Noise parameters to adjust signal amplitude level.

    Returns
    -------
    numpy.ndarray
      Array with output samples
    '''

    ampAll = numpy.sin(userTimeAll_s * self.c) * self.amplitude + self.initial

    ampAll = AmplitudeBase.convertUnits2Amp(ampAll,
                                            self.units,
                                            noiseParams)
    signal *= ampAll

    return signal
def test_AmplitudeBase_convertSNR():
  '''
  Generic tests for AmplitudeBase conversion to volts
  '''
  noiseParams = NoiseParameters(1e6, 1.)
  assert 10. * numpy.log10(4.) == AmplitudeBase.convertUnits2SNR(4.,
                                                                 AmplitudeBase.UNITS_AMPLITUDE,
                                                                 noiseParams)
  assert 10. * numpy.log10(1.) == AmplitudeBase.convertUnits2SNR(4.,
                                                                 AmplitudeBase.UNITS_POWER,
                                                                 noiseParams)
  assert 20. == AmplitudeBase.convertUnits2SNR(100,
                                               AmplitudeBase.UNITS_SNR,
                                               noiseParams)
  assert 15. == AmplitudeBase.convertUnits2SNR(15.,
                                               AmplitudeBase.UNITS_SNR_DB,
                                               noiseParams)
def test_AmplitudeBase_convertVolts():
  '''
  Generic tests for AmplitudeBase conversion to volts
  '''
  noiseParams = NoiseParameters(1e6, 1.)
  assert 4. == AmplitudeBase.convertUnits2Amp(4.,
                                              AmplitudeBase.UNITS_AMPLITUDE,
                                              noiseParams)
  assert 2. == AmplitudeBase.convertUnits2Amp(4.,
                                              AmplitudeBase.UNITS_POWER,
                                              noiseParams)
  assert 20. == AmplitudeBase.convertUnits2Amp(100,
                                               AmplitudeBase.UNITS_SNR,
                                               noiseParams)
  assert 2. == AmplitudeBase.convertUnits2Amp(0.,
                                              AmplitudeBase.UNITS_SNR_DB,
                                              noiseParams)
def test_AmplitudeBase_abstract():
  '''
  Generic tests for AmplitudeBase abstract methods
  '''
  ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR_DB)
  noiseParams = NoiseParameters(1e6, 1.)
  userTimeAll_s = numpy.asarray([0., 1.], dtype=numpy.float)
  signal = numpy.asarray([0., 1.], dtype=numpy.float)
  try:
    ampl.computeSNR(noiseParams)
    assert False
  except NotImplementedError:
    pass
  try:
    ampl.applyAmplitude(signal, userTimeAll_s, noiseParams)
    assert False
  except NotImplementedError:
    pass
def test_AmplitudeBase_units():
    '''
  Generic tests for AmplitudeBase methods
  '''
    ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR)
    assert AmplitudeBase.UNITS_SNR == ampl.getUnits()
    ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR_DB)
    assert AmplitudeBase.UNITS_SNR_DB == ampl.getUnits()
Exemple #10
0
  def computeSNR(self, noiseParams):
    '''
    Computes signal to noise ratio in dB.

    noiseParams : NoiseParameters
      Noise parameter container

    Returns
    -------
    float
      SNR in dB
    '''
    value = self.initial
    return AmplitudeBase.convertUnits2SNR(value, self.units, noiseParams)
Exemple #11
0
  def applyAmplitude(self, signal, userTimeAll_s, noiseParams):
    '''
    Applies amplitude modulation to signal.

    This method applies polynomial modulation.

    Parameters
    ----------
    signal : numpy.ndarray
      Signal sample vector. Each element defines signal amplitude in range
      [-1; +1]. This vector is modified in place.
    userTimeAll_s : numpy.ndarray
      Sample time vector. Each element defines sample time in seconds.
    noiseParams : NoiseParameters
      Noise parameters to adjust signal amplitude level.

    Returns
    -------
    numpy.ndarray
      Array with output samples
    '''

    poly = self.poly
    if poly is not None:
      amplitudeVector = poly(userTimeAll_s)
      amplitudeVector = AmplitudeBase.convertUnits2Amp(amplitudeVector,
                                                       self.units,
                                                       noiseParams)
      signal *= amplitudeVector
    else:
      amplitude = AmplitudeBase.convertUnits2Amp(1.,
                                                 self.units,
                                                 noiseParams)
      signal *= amplitude

    return signal
Exemple #12
0
    def computeSNR(self, noiseParams):
        '''
    Computes signal to noise ratio in dB.

    noiseParams : NoiseParameters
      Noise parameter container

    Returns
    -------
    float
      SNR in dB
    '''
        poly = self.poly
        if poly is not None:
            value = poly(0.)
        else:
            value = 1.

        return AmplitudeBase.convertUnits2SNR(value, self.units, noiseParams)
Exemple #13
0
  def computeSNR(self, noiseParams):
    '''
    Computes signal to noise ratio in dB.

    noiseParams : NoiseParameters
      Noise parameter container

    Returns
    -------
    float
      SNR in dB
    '''
    poly = self.poly
    if poly is not None:
      value = poly(0.)
    else:
      value = 1.

    return AmplitudeBase.convertUnits2SNR(value, self.units, noiseParams)
def test_AmplitudeBase_abstract():
    '''
  Generic tests for AmplitudeBase abstract methods
  '''
    ampl = AmplitudeBase(AmplitudeBase.UNITS_SNR_DB)
    noiseParams = NoiseParameters(1e6, 1.)
    userTimeAll_s = numpy.asarray([0., 1.], dtype=numpy.float)
    signal = numpy.asarray([0., 1.], dtype=numpy.float)
    try:
        ampl.computeSNR(noiseParams)
        assert False
    except NotImplementedError:
        pass
    try:
        ampl.applyAmplitude(signal, userTimeAll_s, noiseParams)
        assert False
    except NotImplementedError:
        pass