def test_frac_time_shift_with_random(self): """ Test frac_time_shift with a random signal""" N = 1024 p, q = (7, 6) # resampling parameters b, a = scipy.signal.butter(10, .25) shifts = (0.5, 1 / 6, numpy.random.uniform(low=-5, high=+5)) for shift in shifts: noise = numpy.pad(numpy.random.rand(N // 2), (N // 4, N // 4)) filt_noise = scipy.signal.filtfilt(b, a, noise) res1 = pb.frac_time_shift( scipy.signal.resample_poly(filt_noise, p, q), p / q * shift) res2 = scipy.signal.resample_poly( pb.frac_time_shift(filt_noise, shift), p, q) error = numpy.max(numpy.abs(res1 - res2)) # ax1 = plt.subplot(2, 2, 1) # ax1.plot(res1, label='resamp/shift') # ax1.plot(res2, '.', label='shift/resamp') # # ax1.legend() # ax1.grid() # # ax2 = plt.subplot(2, 2, 2) # ax2.plot(numpy.abs(res1-res2)) # ax2.grid() # plt.show() self.assertLess(error, 10**pb.LOG10_REJECTION)
def test_frac_time_shift_output_size(self): """ Test frac_time_shift: check input and output sizes match""" N = 1024 shift = numpy.random.uniform(low=-5, high=+5) shifted = pb.frac_time_shift(numpy.zeros(N), shift) self.assertEqual(shifted.size, N)
def test_frac_time_shift_with_sinus(self): """ Test frac_time_shift with sinusoidal signal""" N = 1024 shifts = (0.5, 1 / 6, numpy.random.uniform(low=-5, high=+5)) time = numpy.arange(-N / 2, N / 2) sigma = N / 4 for shift in shifts: time_shifted = time - shift # error = [] for f in numpy.arange( math.floor( (pb.STOPBAND_CUTOFF_F - pb.ROLL_OFF_WIDTH) * N)) / N: phi = 2 * math.pi * numpy.random.rand() signal = sinegauss(time, sigma, f, phi) estimate_shifted = pb.frac_time_shift(signal, shift) exact_shifted = sinegauss(time_shifted, sigma, f, phi) error = numpy.max(numpy.abs(estimate_shifted - exact_shifted)) # error.append(numpy.max(numpy.abs(estimate_shifted-exact_shifted))) self.assertLess(error, 10**pb.LOG10_REJECTION)