def test_arbitrary_on_empty(): fs = 20000.0 # Hz dt = 1 / fs # s time = 0.0 # s n_scans = int(round(time / dt)) t = dt * np.arange(n_scans) x = (0.9 * pow(2, 14) * np.sin(2 * math.pi * 10 * t)).astype('int16').reshape(1, n_scans) # V/whatevers, scale for converting from V to whatever or vice-versa channel_scale = (np.array(1, ndmin=1)).astype('float64') adc_coefficients = (np.array([1, 2, 3, 4])).astype('float64').reshape(1, 4) # identity function xf = x.astype('float64') y_theoretical = 1.0 + 2.0 * xf + 3.0 * xf * xf + 4.0 * xf * xf * xf y = ws.scaled_double_analog_data_from_raw(x, channel_scale, adc_coefficients) assert (y_theoretical == y).all()
def test_arbitrary_on_matrix_zero_coeffs(): fs = 20000.0 # Hz dt = 1 / fs # s time = 0.2 # s n_scans = int(round(time / dt)) n_channels = 0 i_channel = np.arange(n_channels).reshape(n_channels, 1) t = (dt * np.arange(n_scans)).reshape(1, n_scans) x = (0.9 * pow(2, 14) * np.sin(2 * math.pi * 10 * t + 2 * math.pi * (i_channel / n_channels))).astype('int16') channel_scale = 1 / (i_channel + 1) adc_coefficients = np.zeros((n_channels, 0)) y_theoretical = np.zeros(x.shape) y = ws.scaled_double_analog_data_from_raw(x, channel_scale, adc_coefficients) assert (y_theoretical == y).all()
def test_identity_function_on_vector(): fs = 20000.0 # Hz dt = 1 / fs # s time = 0.2 # s n_scans = int(round(time / dt)) t = dt * np.arange(n_scans) x = (0.9 * pow(2, 14) * np.sin(2 * math.pi * 10 * t)).astype('int16').reshape(1, n_scans) channel_scale = (np.array(1, ndmin=1)).astype( 'float64') # V/whatevers, scale for converting from V to whatever or vice-versa adc_coefficients = (np.array([0, 1, 0, 0])).astype('float64').reshape(1, 4) # identity function y_theoretical = x.astype('float64') y = ws.scaled_double_analog_data_from_raw(x, channel_scale, adc_coefficients) # yMex = ws.scaledDoubleAnalogDataFromRawMex(x, channel_scale, adc_coefficients) assert (y_theoretical == y).all()
def test_arbitrary_on_matrix_one_coeff(): fs = 20000.0 # Hz dt = 1 / fs # s time = 0.2 # s n_scans = int(round(time / dt)) n_channels = 6 i_channel = np.arange(n_channels).reshape(n_channels, 1) t = (dt * np.arange(n_scans)).reshape(1, n_scans) x = (0.9 * pow(2, 14) * np.sin(2 * math.pi * 10 * t + 2 * math.pi * (i_channel / n_channels))).astype('int16') channel_scale = 1 / (i_channel + 1) # adc_coefficients = np.tile((np.array([1, 2, 3, 4])).astype('float64').reshape(1, 4), (n_channels,1)) adc_coefficients = np.tile(0.001, (n_channels, 1)) # xf = x.astype('float64') y_theoretical = np.tile(0.001, (n_channels, n_scans)) / channel_scale y = ws.scaled_double_analog_data_from_raw(x, channel_scale, adc_coefficients) assert (y_theoretical == y).all()