def testCutFFTDCArtifacts(self): x = np.linspace( 100, 199, 100 ) # Must not be equal to array index (so we check the fn doesnt just return indices) # Generate down/up slope; minimum at 10 y = np.linspace(0, 100, 100) y[:10] = np.linspace(100, 0, 10) fft = FFT(x, y) # Insert artificial peak self.assertEqual(fft.cut_dc_artifacts(return_idx=True), 10)
def testDominantFrequency(self): x = np.linspace( 100, 199, 100 ) # Must not be equal to array index (so we check the fn doesnt just return indices) y = np.random.random_sample(100) # Insert artificial peak y[32] = 8.0 fft = FFT(x, y) self.assertEqual(fft.dominant_frequency(), 132) # Check with frequency range self.assertEqual(fft.dominant_frequency(low=100.0, high=140.0), 132)
def testCutDCArtifactsNoMinimum(self): # No minimum --> should return original array x = np.linspace(100, 1, 100) y = np.linspace(500, 5, 100) fft = FFT(x, y).cut_dc_artifacts() self.assertEqual(fft.frequencies.shape, x.shape) self.assertEqual(fft.amplitudes.shape, y.shape) assert_allclose(fft.frequencies, x) assert_allclose(fft.amplitudes, y) # Check returned index self.assertEqual(FFT(x, y).cut_dc_artifacts(return_idx=True), 0)
def testNoneLimit(self): arr = np.arange(0.0, 10.0) # Low = None result = FFT(arr, arr + 1.0, None)[:5.0] desired = np.asarray([1.0, 2.0, 3.0, 4.0, 5.0]) assert_allclose(result.frequencies, desired - 1.0) assert_allclose(result.amplitudes, desired) # High = None result = FFT(arr, arr + 1.0, None)[5.0:] desired = np.asarray([6.0, 7.0, 8.0, 9.0, 10.0]) assert_allclose(result.frequencies, desired - 1.0) assert_allclose(result.amplitudes, desired)
def testTupleUnpacking(self): "Test tuple unpacking for FFT inlining" arr = np.arange(0.0, 10.0) result = FFT(arr, arr + 1.0, None)[1.0:5.5] desired = np.asarray([2.0, 3.0, 4.0, 5.0, 6.0]) assert_allclose(result.frequencies, desired - 1.0) assert_allclose(result.amplitudes, desired)
def testGeneric(self): arr = np.arange(0.0, 10.0) result = FFT(arr, arr + 1.0, None)[1.0:5.5] desired = np.asarray([2.0, 3.0, 4.0, 5.0, 6.0]) assert_allclose(result.frequencies, desired - 1.0) assert_allclose(result.amplitudes, desired)
def test_find_closest_value_angle(self): fftx = np.asarray([1, 2, 3, 4, 5]) fft = FFT(fftx, fftx * 2, fftx * 3) self.assertEqual((1, 2, 3), fft.closest_value(0.))
def test_find_closest_frequency(self): fftx = np.asarray([1, 2, 3, 4, 5]) fft = FFT(fftx, fftx * 2) self.assertEqual(1, fft.closest_frequency(0.))
def testAmplitudeIntegral(self): fft = FFT(np.arange(4), np.asarray([2, 3, 4, 5]), None) assert_almost_equal(fft.amplitude_integral(), sum(fft.amplitudes) / 3.) assert_almost_equal(fft.amplitude_integral(low=1., high=2.01), 3 + 4)
def test_find_closest_value_noangle(self): fftx = np.asarray([1, 2, 3, 4, 5]) fft = FFT(fftx, fftx * 2) assert_equal((1, 2, None), fft.closest_value(0.))