In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pickle
In [5]:
#Let's first create a toy example
test = np.array([10,14,15,16,17,18,24,32,33,34,100],dtype=np.int32)
print test
#now shift 4 bit right and shift back
print test >> 4 << 4
In [2]:
#change the data to milli-Volt
#now if I have a 24 bit dada that have a sensitiviy 9.97 v/g
#read in data
data = pickle.load( open( "data.p", "rb" ) )
#change to milli volt
data_milliVolt = np.array(data)* 10**6 * 9.97
In [8]:
#shift the binary 8 bit to the right, and the shift it back, this
#will convert 24bit data to 16bit data
converted_data = data_milliVolt.astype(np.int32) >> 8 << 8
converted_data = converted_data / 9.97 / 10**6
In [9]:
plt.plot(data, label = 'Raw data')
plt.plot(converted_data, label = 'Converted data')
plt.legend()
plt.show()
In [16]:
#shift the binary 8 bit to the right, and the shift it back, this
#will convert 24bit data to 12bit data
converted_data = data_milliVolt.astype(np.int32) >> 12 << 12
converted_data = converted_data / 9.97 / 10**6
In [17]:
plt.plot(data)
plt.plot(converted_data)
plt.show()
In [ ]: