def check_czt(x): # Check that czt is the equivalent of normal fft y = fft(x) y1 = czt(x) assert_allclose(y1, y, rtol=1e-13) # Check that interpolated czt is the equivalent of normal fft y = fft(x, 100 * len(x)) y1 = czt(x, 100 * len(x)) assert_allclose(y1, y, rtol=1e-12)
def test_czt_math(impulse, m, w, a): # z-transform of an impulse is 1 everywhere assert_allclose(czt(impulse[2:], m=m, w=w, a=a), np.ones(m), rtol=1e-10) # z-transform of a delayed impulse is z**-1 assert_allclose(czt(impulse[1:], m=m, w=w, a=a), czt_points(m=m, w=w, a=a)**-1, rtol=1e-10) # z-transform of a 2-delayed impulse is z**-2 assert_allclose(czt(impulse, m=m, w=w, a=a), czt_points(m=m, w=w, a=a)**-2, rtol=1e-10)
def test_nonsense_size(size): # Numpy and Scipy fft() give ValueError for 0 output size, so we do, too with pytest.raises(ValueError, match='Invalid number of CZT'): CZT(size, 3) with pytest.raises(ValueError, match='Invalid number of CZT'): ZoomFFT(size, 0.2, 3) with pytest.raises(ValueError, match='Invalid number of CZT'): CZT(3, size) with pytest.raises(ValueError, match='Invalid number of CZT'): ZoomFFT(3, 0.2, size) with pytest.raises(ValueError, match='Invalid number of CZT'): czt([1, 2, 3], size) with pytest.raises(ValueError, match='Invalid number of CZT'): zoom_fft([1, 2, 3], 0.2, size)
def test_large_prime_lengths(): np.random.seed(0) # Deterministic randomness for N in (101, 1009, 10007): x = np.random.rand(N) y = fft(x) y1 = czt(x) assert_allclose(y, y1, rtol=1e-12)
def test_int_args(): # Integer argument `a` was producing all 0s assert_allclose(abs(czt([0, 1], m=10, a=2)), 0.5 * np.ones(10), rtol=1e-15) assert_allclose(czt_points(11, w=2), 1 / (2**np.arange(11)), rtol=1e-30)
def test_0_rank_input(): with pytest.raises(IndexError, match='tuple index out of range'): czt(5) with pytest.raises(IndexError, match='tuple index out of range'): zoom_fft(5, 0.5)
def test_empty_input(): with pytest.raises(ValueError, match='Invalid number of CZT'): czt([]) with pytest.raises(ValueError, match='Invalid number of CZT'): zoom_fft([], 0.5)
def test_czt_vs_fft(): np.random.seed(123) random_lengths = np.random.exponential(100000, size=10).astype('int') for n in random_lengths: a = np.random.randn(n) assert_allclose(czt(a), fft(a), rtol=1e-11)