def runMainLoop(self, directory):
				#setup directory for correlated traces
		dataFolderDirectory = directory
		#create arrays that contain all the .trc files for both chan 1 and chan 2 (Separate)
		globPathNameChanOne = dataFolderDirectory + '/C1*.trc'
		globPathNameChanTwo = dataFolderDirectory + '/C2*.trc'
		fileArrayOne = glob.glob(globPathNameChanOne)
		fileArrayTwo = glob.glob(globPathNameChanTwo)

		#setup to progress through entire array of .trc files
		numTraces = len(fileArrayOne)
		fileArrayIndex = 0

		#perform a while loop to progress through the individual correlated trace measurements
		while (fileArrayIndex < numTraces):
			#extract data from .trc files associated with the current index counter into arrays of data
			fileChanOne = fileArrayOne[fileArrayIndex]
			fileChanTwo = fileArrayTwo[fileArrayIndex]
			timeAxis = lecroyparser.ScopeData(fileChanOne).x
			dataChanOne = lecroyparser.ScopeData(fileChanOne).y
			dataChanTwo = lecroyparser.ScopeData(fileChanTwo).y

			if fileArrayIndex == 0:
				sumChanOne = dataChanOne[0:self.numSamples]
				sumChanTwo = dataChanTwo[0:self.numSamples]
			else:
				sumChanOne += dataChanOne[0:self.numSamples]
				sumChanTwo += dataChanTwo[0:self.numSamples]

			if (fileArrayIndex % updateEveryXTraces == 0) :
				updatePlotsFlag = True
			else:
				updatePlotsFlag = False

			#process correlated channels as desired
			#show user what traces look like
			self.plotBothChannels(dataChanOne, dataChanTwo, updatePlotsFlag)

			#go into the ringing range and add that fourier component to an ongoign sum
			self.addNewTraceRinging(dataChanTwo, updatePlotsFlag, dataChanOne, fileArrayIndex)

			#process the current traces to add their hits to the growing histograms
			self.addToHistograms(dataChanOne, dataChanTwo, updatePlotsFlag)

			#increment the file array index to proceed to the next trace
			fileArrayIndex += 1

			if updatePlotsFlag :
				plt.plot(self.timeAxis, sumChanOne)
				plt.plot(self.timeAxis, sumChanTwo)
				plt.xlim([0, 1e-7])
				plt.draw()
				#plt.waitforbuttonpress()
				plt.pause(0.1)


		return self.energyHistogramOne, self.energyVector
Exemple #2
0
def getHeaderBytesTimes(fname):
    data = lecroyparser.ScopeData(fname)
    nvals = len(data.y)
    f = open(fname, 'br')
    buf = f.read()
    f.close()
    nseek = int(len(buf) - 2 * nvals)
    return (nseek, nvals, data.x)
Exemple #3
0
 def get_channel(self, channel='C1'):
     # read channel data
     if (self.scope):
         cmd = self.scope.write('{0}:WF? DATA1'.format(channel))
         trc = self.scope.read_raw()
         newFile = open("filename.txt", "wb")
         newFile.write(trc)
         time.sleep(2)
         data = lecroyparser.ScopeData('filename.txt')
         return [data.x, data.y]
     else:
         return None
Exemple #4
0
def readInDataFromFolderWithTime():
    global fileArrayIndex
    fileNameNow = fileArray[fileArrayIndex]
    dataNow = lecroyparser.ScopeData(fileNameNow)
    fileArrayIndex += 1
    return dataNow.y, dataNow.x
	def runMainLoop(self, directory):
				#setup directory for correlated traces
		dataFolderDirectory = directory
		#create arrays that contain all the .trc files for both chan 1 and chan 2 (Separate)
		globPathNameChanOne = dataFolderDirectory + '/C1*.trc'
		globPathNameChanTwo = dataFolderDirectory + '/C2*.trc'
		fileArrayOne = glob.glob(globPathNameChanOne)
		fileArrayTwo = glob.glob(globPathNameChanTwo)

		#setup to progress through entire array of .trc files
		numTraces = len(fileArrayOne)
		freqCutoffLow = 0
		freqCutoffHigh = 400
		freqSamplesToKeep = freqCutoffHigh - freqCutoffLow
		fileArrayIndex = 0

		traceStrengths = np.zeros(numTraces)
		ringingStrengths = np.zeros(numTraces)
		amplitudesSpans = np.zeros(numTraces)

		#perform a while loop to progress through the individual correlated trace measurements
		while (fileArrayIndex < numTraces):
			#extract data from .trc files associated with the current index counter into arrays of data
			fileChanOne = fileArrayOne[fileArrayIndex]
			fileChanTwo = fileArrayTwo[fileArrayIndex]
			timeAxis = lecroyparser.ScopeData(fileChanOne).x
			timeAxis = timeAxis * 1e9
			dataChanOne = lecroyparser.ScopeData(fileChanOne).y
			dataChanTwo = lecroyparser.ScopeData(fileChanTwo).y

			if fileArrayIndex == 0:
				#create frequency axis
				numSamples = timeAxis.size
				self.freqAxis = Fs* np.linspace(0, numSamples-1, numSamples) / numSamples
				spectralMap = np.zeros((numTraces, freqSamplesToKeep))

			triggerStrength = np.sum(dataChanTwo)
			ampSpan = np.amax(dataChanOne) - np.amin(dataChanOne)
			chanOneSpectral = fft(dataChanOne)
			absFFT = np.absolute(chanOneSpectral)
			powerSpectrum = np.square(absFFT)

			traceStrengths[fileArrayIndex] = -1*triggerStrength*0.025
			spectralMap[fileArrayIndex, :] = powerSpectrum[freqCutoffLow:freqCutoffHigh]
			ringingStrengths[fileArrayIndex] = np.sum(powerSpectrum[freqCutoffLow:freqCutoffHigh])
			amplitudesSpans[fileArrayIndex] = ampSpan

			if False and ((fileArrayIndex % updateEveryXTraces) == 0):
				#clear previous lines
				linesOld = self.axisTracesHigh.lines
				for i in range(len(linesOld)):
					lineToDel = linesOld.pop(0)
					del lineToDel
				linesOld = self.axisTracesLow.lines
				for i in range(len(linesOld)):
					lineToDel = linesOld.pop(0)
					del lineToDel
				plt.sca(self.axisTracesHigh)
				plt.plot(timeAxis, dataChanTwo, c='tab:blue')
				plt.xticks(fontsize=26)
				plt.yticks(fontsize=26)
				# self.axisTracesHigh.set_xlim((25e-9, 1e-7))
				plt.sca(self.axisTracesLow)
				plt.plot(timeAxis, 1000*dataChanOne, c='tab:orange')
				plt.xticks(fontsize=26)
				plt.yticks(fontsize=26)
				# self.axisTracesLow.set_xlim((25e-9, 1e-7))
				plt.draw()

				linesOld = self.axisPowerSpectrum.lines
				for i in range(len(linesOld)):
					lineToDel = linesOld.pop(0)
					del lineToDel
				plt.figure(self.figHandleFourier.number)
				plt.plot(self.freqAxis/1e9, powerSpectrum)
				plt.xticks(fontsize=26)
				plt.yticks(fontsize=26)
				plt.draw()
				plt.pause(0.001)

				# plt.waitforbuttonpress()
				breakpoint()

			#increment the file array index to proceed to the next trace
			fileArrayIndex += 1

		sortKeys = np.argsort(traceStrengths)
		sortedSpectralMap = spectralMap[sortKeys, :]

		# breakpoint()
		heatMapHandle = plt.figure(figsize=(9,6))
		heatMapHandle.add_axes([0.2, 0.2, 0.7, 0.7])
		temp = np.linspace(0, numTraces-1, numTraces)
		tempFreq = self.freqAxis[freqCutoffLow:freqCutoffHigh]
		plt.pcolormesh(tempFreq*1e-9, temp, np.log(sortedSpectralMap), shading='auto', vmin=-1, vmax=2.5)
		plt.colorbar()
		plt.xlim(freqLimits)
		plt.title("Tracking log(Spectral Power)", fontsize=30)
		plt.xlabel("Frequency (GHz)", fontsize=30)
		plt.ylabel("Unique Measurements\n", fontsize=30)
		plt.yticks([], fontsize=26)
		plt.xticks(freqTicks, fontsize=26)
		plt.draw()

		plt.figure(figHandleRingStrength.number)
		scatNow = plt.scatter(traceStrengths, ringingStrengths, s=1)
		scatterList.append(scatNow)
		plt.draw()
		plt.pause(0.001)
Exemple #6
0
    def _set_orderOfMagnitude(self, range):
        """Over-riding this to avoid having orderOfMagnitude reset elsewhere"""
        self.orderOfMagnitude = self._order_of_mag


if len(sys.argv) < 2:
    print("Usage: %s <filename>", sys.argv[0])

path = sys.argv[1]

c2path = path.replace("C3--Trace", "C2--Trace")
c3path = path.replace("C2--Trace", "C3--Trace")
print(c2path)
print(c3path)

c2 = lecroyparser.ScopeData(c2path)
c3 = lecroyparser.ScopeData(c3path)

fig, ax1 = plt.subplots()

color = 'tab:red'
ax1.set_xlabel('Time in s', fontsize=fontsize)
ax1.set_ylabel('EM-Signal (Volt)', color=color, fontsize=fontsize)
ax1.plot(c2.x, c2.y, color=color)
ax1.tick_params(axis='y', labelcolor=color)

ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis

color = 'tab:blue'
ax2.set_ylabel('Volt', color=color,
               fontsize=fontsize)  # we already handled the x-label with ax1
plt.xticks([i*1e-9 for i in range(0,3600,500)],fontsize=fontsize)
plt.yticks([i*0.01 for i in range(-10,8,2)],fontsize=fontsize)



if len(sys.argv) < 2:
    print("Usage: %s <path>",sys.argv[0])


prefix = sys.argv[1]
if prefix[-1] != "/":
    prefix += "/"

for i in range(15,-1,-1):
    numstr = str(i)
    while len(numstr) < 5:
        numstr = "0"+numstr
    curpath = prefix + "C2--Trace--"+numstr+".trc"
    print(curpath)
    data = lecroyparser.ScopeData(curpath)
    plt.plot(data.x,data.y)

plt.xlabel('Time in s', fontsize=fontsize)
plt.ylabel('EM-Signal (Volt)', fontsize=fontsize)


title = "Multiple block decryptions"

plt.title(title, fontsize=fontsize)
plt.show()
Exemple #8
0
def parse_file(datafile: str, vendor: str) -> object:
    if vendor == 'lecroy':
        data = lecroyparser.ScopeData(datafile)
    if vendor == 'tek':
        data = tek.ScopeData(datafile)
    return data