예제 #1
0
 def test_compare_with_inversion(self):
     """
     Creates a Signal, transforms it, inverses the transformation and tests, if it resembles the original Signal.
     """
     ifft = sumpf.modules.InverseFourierTransform()
     sumpf.connect(self.fft.GetSpectrum, ifft.SetSpectrum)
     insignal = self.gen.GetSignal()
     outsignal = ifft.GetSignal()
     common.compare_signals_almost_equal(testcase=self, signal1=insignal, signal2=outsignal)
예제 #2
0
 def test_cosine2sine(self):
     """
     Tests, if a cosine can be transformed to a sine wave with the
     IntegrateSignal class.
     """
     frequency = 200.0
     cosine = sumpf.modules.SineWaveGenerator(frequency=frequency, phase=math.pi / 2.0, length=1000).GetSignal()
     integral = sumpf.modules.IntegrateSignal(signal=cosine, offset=sumpf.modules.IntegrateSignal.NO_DC).GetOutput()
     scaled = 2.0 * math.pi * frequency * integral
     sine = sumpf.modules.SineWaveGenerator(frequency=frequency, phase=0.0, length=1000).GetSignal()
     common.compare_signals_almost_equal(testcase=self, signal1=scaled, signal2=sine, places=1)
예제 #3
0
 def test_compare_with_filter(self):
     """
     Compares the Laguerre functions from this generator with those that have
     been created in the frequency domain.
     """
     time_laguerre = self.__GetOrdinaryLaguerreFunctions()
     properties = sumpf.modules.ChannelDataProperties(signal_length=len(time_laguerre[0][0]), samplingrate=time_laguerre[0][0].GetSamplingRate())
     frequency_laguerre = []
     gen = sumpf.modules.LaguerreFilterGenerator(resolution=properties.GetResolution(), length=properties.GetSpectrumLength())
     for s in range(3):
         frequency_laguerre.append([])
         for o in [0, 1, 4]:
             gen.SetOrder(o)
             gen.SetScalingFactor(scaling_factor=10.0 * (s + 1.0))
             function = sumpf.modules.InverseFourierTransform(spectrum=gen.GetSpectrum()).GetSignal()
             frequency_laguerre[s].append(function * function.GetSamplingRate())
     for a in range(len(time_laguerre)):
         for b in range(len(time_laguerre[a])):
             common.compare_signals_almost_equal(testcase=self,
                                                 signal1=time_laguerre[a][b][1500:-1500],
                                                 signal2=frequency_laguerre[a][b][1500:-1500],
                                                 places=3,
                                                 compare_labels=False)
예제 #4
0
 def test_sine(self):
     """
     Tests the derivative of a sine wave Signal.
     """
     frequency = 1.9
     samplingrate = 48000
     length = 5 * samplingrate
     sin = sumpf.modules.SineWaveGenerator(frequency=frequency,
                                           phase=0.0,
                                           samplingrate=samplingrate,
                                           length=length)
     cos = sumpf.modules.SineWaveGenerator(frequency=frequency,
                                           phase=math.pi / 2.0,
                                           samplingrate=samplingrate,
                                           length=length)
     drv = sumpf.modules.DifferentiateSignal()
     places = 2
     if common.lib_available("numpy"):
         drv.SetFunction(lambda sequence: sumpf.helper.differentiate_spline(sequence=sequence, degree=2))
         places = 6
     self.assertEqual(drv.GetOutput(), sumpf.Signal())
     drv.SetInput(sin.GetSignal())
     common.compare_signals_almost_equal(self, drv.GetOutput(), cos.GetSignal() * (2.0 * math.pi * frequency), places)
예제 #5
0
 def test_derivative(self):
     """
     Compares the derivative of the integral with the original Signal.
     """
     noise = sumpf.modules.NoiseGenerator(
         distribution=sumpf.modules.NoiseGenerator.RedNoise(), length=900, samplingrate=1000.0
     )
     noise.Seed(13)
     cache = (
         sumpf.modules.PassThroughSignal()
     )  # avoid regeneration of the random noise Signal even if caching is turned off
     sumpf.connect(noise.GetSignal, cache.SetSignal)
     integral = sumpf.modules.IntegrateSignal()
     sumpf.connect(cache.GetSignal, integral.SetInput)
     derivative = sumpf.modules.DifferentiateSignal()
     sumpf.connect(integral.GetOutput, derivative.SetInput)
     common.compare_signals_almost_equal(
         testcase=self, signal1=cache.GetSignal()[1:-1], signal2=derivative.GetOutput()[1:-1], places=12
     )
     integral.SetOffset(129.874)
     common.compare_signals_almost_equal(
         testcase=self, signal1=cache.GetSignal()[1:-1], signal2=derivative.GetOutput()[1:-1], places=10
     )
예제 #6
0
 def test_cython(self):
     thiele_small_parameters = sumpf.ThieleSmallParameters()
     sweep = sumpf.modules.SweepGenerator(start_frequency=10.0, stop_frequency=10000.0, function=sumpf.modules.SweepGenerator.LINEAR, samplingrate=44100.0, length=2 ** 2).GetSignal()
     python = sumpf.modules.ThieleSmallParameterAuralizationNonlinear(thiele_small_parameters=thiele_small_parameters,
                                                                      voltage_signal=sweep,
                                                                      listener_distance=2.9,
                                                                      medium_density=1.5,
                                                                      warp_frequency=33.2,
                                                                      regularization=0.1,
                                                                      save_samples=True,
                                                                      use_cython=False)
     cython = sumpf.modules.ThieleSmallParameterAuralizationNonlinear(thiele_small_parameters=thiele_small_parameters,
                                                                      voltage_signal=sweep,
                                                                      listener_distance=2.9,
                                                                      medium_density=1.5,
                                                                      warp_frequency=33.2,
                                                                      regularization=0.1,
                                                                      save_samples=True,
                                                                      use_cython=True)
     self.assertEqual(python.GetCurrent(), cython.GetCurrent())
     sine = sumpf.modules.SineWaveGenerator(frequency=443.9, samplingrate=48000.0, length=2 ** 7).GetSignal()
     python.SetVoltage(sine)
     cython.SetVoltage(sine)
     common.compare_signals_almost_equal(self, signal1=python.GetSoundPressure(), signal2=cython.GetSoundPressure(), places=11)