Exemple #1
0
 def __proc(self, sensor, a):
     """Utility function to do the heavy lifting"""
     goodlist = list()
     tree = list()
     counter = float()
     retlist = list()
     while not len(tree) == FFT_SIZE:
         stuff = a.get128more(sensor)
         tree += stuff
         #time.sleep(1)
         counter += 1
     while True:
         try:
             inittime = time.time()
             artree = PreprocessUtils.highpass(tree)
             win32 = numpy.hanning(512)
             artree = numpy.array(artree)
             stuff1 = win32 * artree
             stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 8, 12, 30],
                                                128)
             stuff4 = abs(20 * numpy.log(stuff2))
             stuff5 = tuple(stuff4[0])
             retlist.append(stuff5)
             goodlist.append(stuff5)
             ##print(len(tree))
             del tree[0:16]
             more16 = a.get16more(sensor)
             tree += more16
             #time.sleep((0.125-(time.time()-inittime)))
             counter += (0.125)
         except:
             return retlist
Exemple #2
0
 def __proc(self, sensor, a):
     """Utility function to do the heavy lifting"""
     goodlist=list()
     tree=list()
     counter=float()
     retlist=list()
     while not len(tree)==FFT_SIZE:
        stuff=a.get128more(sensor)
        tree+=stuff
        #time.sleep(1)
        counter+=1
     while True:
         try:
             inittime=time.time()
             artree=PreprocessUtils.highpass(tree)
             win32=numpy.hanning(512)
             artree=numpy.array(artree)
             stuff1=win32*artree
             stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
             stuff4=abs(20*numpy.log(stuff2))
             stuff5=tuple(stuff4[0])
             retlist.append(stuff5)   
             goodlist.append(stuff5)
             ##print(len(tree))
             del tree[0:16]
             more16=a.get16more(sensor)
             tree+=more16
             #time.sleep((0.125-(time.time()-inittime)))
             counter+=(0.125)
         except:
             return retlist
Exemple #3
0
def bplot(file, sensor, rects1, a, fig):
    #file2w=open("C:/Users/Gaurav/Desktop/fc51-fft.txt", "w")
    goodlist = list()
    tree = list()
    counter = float()
    while not len(tree) == FFT_SIZE:
        print("s")
        stuff = a.get128more(sensor)
        tree += stuff
        #time.sleep(1)
        counter += 1
    while True:
        inittime = time.time()
        artree = PreprocessUtils.highpass(tree)
        win32 = numpy.hanning(512)
        artree = numpy.array(artree)
        stuff1 = win32 * artree
        stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 7, 13, 30], 128)
        stuff4 = abs(20 * numpy.log(stuff2))
        stuff5 = tuple(stuff4[2])
        print(str(stuff5) + "-" + str(counter))
        goodlist.append(stuff5)
        del tree[0:16]
        more16 = a.get16more(sensor)
        tree += more16
        #time.sleep((0.125-(time.time()-inittime)))
        counter += (0.125)
Exemple #4
0
def bplot(file, sensor, rects1, a, fig):
    #file2w=open("C:/Users/Gaurav/Desktop/fc51-fft.txt", "w")
    goodlist=list()
    tree=list()
    counter=float()
    while not len(tree)==FFT_SIZE:
       print("s")
       stuff=a.get128more(sensor)
       tree+=stuff
       #time.sleep(1)
       counter+=1
    while True:
        inittime=time.time()
        artree=PreprocessUtils.highpass(tree)
        win32=numpy.hanning(512)
        artree=numpy.array(artree)
        stuff1=win32*artree
        stuff2=PreprocessUtils.bin_power(stuff1, [1,4,7,13,30], 128)
        stuff4=abs(20*numpy.log(stuff2))
        stuff5=tuple(stuff4[2])
        print(str(stuff5)+"-"+str(counter))        
        goodlist.append(stuff5)
        del tree[0:16]
        more16=a.get16more(sensor)
        tree+=more16
        #time.sleep((0.125-(time.time()-inittime)))
        counter+=(0.125)
Exemple #5
0
def animated_barplot(file,step,how_muc,size):
    # http://www.scipy.org/Cookbook/Matplotlib/Animations
    print("l")
    a=CSV_Extractor.CSVExtractor(file)
    b=a.get_data_from_sensor("FC5", how_much)
    chunk0=0
    chunk1=size
    print("G")
    rects = plt.bar(range(1), 0,  align = 'center')
    rect1=plt.bar(2, 0,  align = 'center')
    rect2=plt.bar(3, 0,  align = 'center')
    rect3=plt.bar(4, 0,  align = 'center')
    print(len(b)/128)
    for i in range(int(len(b)/step)):
        dat=b[chunk0:chunk1]
        r=PreprocessUtils.butter_highpass_filter(dat,0.16,128,5)
        c=PreprocessUtils.basic_window(r)
        #print((len(c),i))
        er=PreprocessUtils.bin_power(c, [1,4,7,13,30], 128)
        j.append(er[1][0])
        for rect in rects:
            #print(er[1][0])
            rect.set_height(er[1][0])
        for rect in rect1:
            rect.set_height(er[1][1])
        for rect in rect2:
            rect.set_height(er[1][2])
        for rect in rect3:
            rect.set_height(er[1][3])
        chunk0+=step
        chunk1+=step
        fig.canvas.draw()
        time.sleep(0.0625)
Exemple #6
0
 def mainloop(self, q,q2,st):
     j={'F3':[], 'O2':[], 'O1':[], 'F8':[], 'F4':[], 'FC6':[], 'AF3':[], 'P7':[], 'P8':[], 'FC5':[], 'T8':[], 'AF4':[], 'F7':[], 'T7':[]}
     b={}
     #q2.put("Hi")
     firstdat=q.recv()
     #fileh=open("C:/Users/Gaurav/Desktop/Testlogs.txt", "w")
     #fileh.write(str(firstdat))
     #fileh.close()
     #q2.put('Hi')
     if type(firstdat)==str:q2.put(firstdat)
     #if firstdat=="j":q2.put("j")
     for i in self.sensors:
         current=firstdat[i]
         b[i]=current
         artree=PreprocessUtils.highpass(current)
         win32=numpy.hanning(512)
         artree=numpy.array(artree)
         stuff1=win32*artree
         stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
         stuff4=abs(20*numpy.log(stuff2))
         stuff5=tuple(stuff4[0])
         j[i].append(stuff5)
         #time.sleep(16/128)
     q2.send(j)
     while True:
         
         secondat=q.recv()
         #q2.send("recieved one")
         #fileh=open("C:/Users/Gaurav/Desktop/Testlogs.txt", "w")
         #fileh.write(str(secondat))
         #fileh.close()
         #q2.put('Hi')
         if type(secondat)==str:q2.put(secondat)
         #if str(secondat)=="die": q2.put("die");break
         for i in self.sensors:
             current=b[i]
             del current[0:16]
             current+=secondat[i]
             #q2.put(len(current))
             b[i]=current
             artree=PreprocessUtils.highpass(current)
             #q2.send("Highpass")
             win32=numpy.hanning(512)
             artree=numpy.array(artree)
             stuff1=win32*artree
             stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
             stuff4=abs(20*numpy.log(stuff2))
             stuff5=tuple(stuff4[0])
             j[i].append(stuff5)
             #time.sleep(16/128)
         #if len(j["FC5"])==st:
         q2.send(j)
         for i in j.keys():
             j[i]=[]
Exemple #7
0
 def mainloop(self, q, q2, st):
     j = {
         'F3': [],
         'O2': [],
         'O1': [],
         'F8': [],
         'F4': [],
         'FC6': [],
         'AF3': [],
         'P7': [],
         'P8': [],
         'FC5': [],
         'T8': [],
         'AF4': [],
         'F7': [],
         'T7': []
     }
     b = {}
     firstdat = q.get()
     if firstdat == "j": q2.put("j")
     for i in self.sensors:
         current = firstdat[i]
         b[i] = current
         artree = PreprocessUtils.highpass(current)
         win32 = numpy.hanning(512)
         artree = numpy.array(artree)
         stuff1 = win32 * artree
         stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 8, 12, 30], 128)
         stuff4 = abs(20 * numpy.log(stuff2))
         stuff5 = tuple(stuff4[0])
         j[i].append(stuff5)
         time.sleep(16 / 128)
     while not q.empty():
         secondat = q.get()
         if str(secondat) == "die":
             q2.put("die")
             break
         for i in self.sensors:
             current = b[i]
             del current[0:16]
             current += secondat[i]
             b[i] = current
             artree = PreprocessUtils.highpass(current)
             win32 = numpy.hanning(512)
             artree = numpy.array(artree)
             stuff1 = win32 * artree
             stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 8, 12, 30],
                                                128)
             stuff4 = abs(20 * numpy.log(stuff2))
             stuff5 = tuple(stuff4[0])
             j[i].append(stuff5)
             time.sleep(16 / 128)
         if len(j[0]) == 1:
             q.put(j)
Exemple #8
0
 def makebinpower(self,firstlist:dict):
     for i in firstlist.key():
         artree=PreprocessUtils.highpass(self.firstlist[i])
         win32=numpy.hanning(512)
         artree=numpy.array(artree)
         stuff1=win32*artree
         stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
         stuff4=abs(20*numpy.log(stuff2))
         stuff5=tuple(stuff4[0])
         retlist.append(stuff5)   
         #goodlist.append(stuff5)
     return retlist
Exemple #9
0
 def mainloop(self):
     self.subprocess=subprocess.Popen(self.subprocess_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
     self.socket.listen(1)
     self.carryover=dict()
     self.finaldict=dict()
     #self.newsocket, ip=self.socket.accept()
     data=b''
     tmpdata=b''
     done=False
     self.firstlist=pickle.loads(data)
     for i in self.firstlist.keys():
         artree=PreprocessUtils.highpass(self.firstlist[i])
         win32=numpy.hanning(512)
         artree=numpy.array(artree)
         stuff1=win32*artree
         stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
         stuff4=abs(20*numpy.log(stuff2))
         stuff5=tuple(stuff4[0])
         goodlist[i].append(stuff5)
     done=True
     while(self.subprocess.poll()==None):
         data=b''
         while (1):
             tmpdata=self.newsocket.recv(4096)
             if tmpdata is not None:
                 data=data+tmpdata
             else:
                 break
         if data==b'':
             return 
         self.carryover=pickle.loads(data)
         for i in self.carryover.keys():
             self.firstlist[i].append(self.carryover[i])
             del self.firstlist[i][0:16]
         for i in self.firstlist.key():
             artree=PreprocessUtils.highpass(self.firstlist[i])
             win32=numpy.hanning(512)
             artree=numpy.array(artree)
             stuff1=win32*artree
             stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
             stuff4=abs(20*numpy.log(stuff2))
             stuff5=tuple(stuff4[0])
             retlist.append(stuff5)   
             goodlist[i].append(stuff5)
         self.detector.update(goodlist)
         if self.detector.detect():
Exemple #10
0
 def mainloop(self, q,q2,st):
     j={'F3':[], 'O2':[], 'O1':[], 'F8':[], 'F4':[], 'FC6':[], 'AF3':[], 'P7':[], 'P8':[], 'FC5':[], 'T8':[], 'AF4':[], 'F7':[], 'T7':[]}
     b={}
     firstdat=q.get()
     if firstdat=="j":q2.put("j")
     for i in self.sensors:
         current=firstdat[i]
         b[i]=current
         artree=PreprocessUtils.highpass(current)
         win32=numpy.hanning(512)
         artree=numpy.array(artree)
         stuff1=win32*artree
         stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
         stuff4=abs(20*numpy.log(stuff2))
         stuff5=tuple(stuff4[0])
         j[i].append(stuff5)
         time.sleep(16/128)
     while not q.empty():
         secondat=q.get()
         if str(secondat)=="die": q2.put("die");break
         for i in self.sensors:
             current=b[i]
             del current[0:16]
             current+=secondat[i]
             b[i]=current
             artree=PreprocessUtils.highpass(current)
             win32=numpy.hanning(512)
             artree=numpy.array(artree)
             stuff1=win32*artree
             stuff2=PreprocessUtils.bin_power(stuff1, [1,4,8,12,30], 128)
             stuff4=abs(20*numpy.log(stuff2))
             stuff5=tuple(stuff4[0])
             j[i].append(stuff5)
             time.sleep(16/128)
         if len(j[0])==1:
             q.put(j) 
Exemple #11
0
def rollingbarplot(file, step, size,sensor):
    a=CSV_Extractor.CSVExtractor(file)
    proc=Preprocessers.DataProcessor()
    temproc=Preprocessers.DataProcessor()
    rects = plt.bar(range(1), 0,  align = 'center')
    rect1=plt.bar(2, 0,  align = 'center')
    rect2=plt.bar(3, 0,  align = 'center')
    rect3=plt.bar(4, 0,  align = 'center')
    tree={'F3': [], 'FC5': [], 'T7': [], 'F7': [], 'P7': [], 'P8': [], 'AF4': [], 'O2': [], 'O1': [], 'T8': [], 'AF3': [], 'FC6': [], 'F4': [], 'F8': []}
    step=False
    binnedstuff=dict()
    while not len(tree["F3"])==size:
        for i in a.sensor2column:
            fed=a.get128more(i)
           # fed={i:fed}
            fed=PreprocessUtils.butter_highpass_filter(fed,0.16, 128,1)
            #temproc.update_data(fed)
            #temproc.do_high_pass()
            #fed=temproc.data_dict
            tree[i]+=fed
    while True:
        if len(tree[0])==size:
                #Now it is time to actually do the calculations
            proc.update_data(tree)
            proc.do_hann_wndow()
            proc.do_bin_power()
            binnedstuff=proc.data_dict
            interestingbinnedstuff=proc.data_dict[sensor][1]
        else:break
        for rect in rects:
            #print(er[1][0])
            rect.set_height(interestingbinnedstuff[0])
        for rect in rect1:
            rect.set_height(interestingbinnedstuff[1])
        for rect in rect2:
            rect.set_height(interestingbinnedstuff[2])
        for rect in rect3:
            rect.set_height(interestingbinnedstuff[3])
        for i in tree:
            del tree[i][0:16]            
        time.sleep(16/128)
        for i in tree:
            tree[i]+=a.get16more(i)
Exemple #12
0
    def mainloop(self, q, q2, st):
        j = {
            'F3': [],
            'O2': [],
            'O1': [],
            'F8': [],
            'F4': [],
            'FC6': [],
            'AF3': [],
            'P7': [],
            'P8': [],
            'FC5': [],
            'T8': [],
            'AF4': [],
            'F7': [],
            'T7': []
        }
        b = {}
        #q2.put("Hi")
        firstdat = q.recv()
        #fileh=open("C:/Users/Gaurav/Desktop/Testlogs.txt", "w")
        #fileh.write(str(firstdat))
        #fileh.close()
        #q2.put('Hi')
        if type(firstdat) == str: q2.put(firstdat)
        #if firstdat=="j":q2.put("j")
        for i in self.sensors:
            current = firstdat[i]
            b[i] = current
            artree = PreprocessUtils.highpass(current)
            win32 = numpy.hanning(512)
            artree = numpy.array(artree)
            stuff1 = win32 * artree
            stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 8, 12, 30], 128)
            stuff4 = abs(20 * numpy.log(stuff2))
            stuff5 = tuple(stuff4[0])
            j[i].append(stuff5)
            #time.sleep(16/128)
        q2.send(j)
        while True:

            secondat = q.recv()
            #q2.send("recieved one")
            #fileh=open("C:/Users/Gaurav/Desktop/Testlogs.txt", "w")
            #fileh.write(str(secondat))
            #fileh.close()
            #q2.put('Hi')
            if type(secondat) == str: q2.put(secondat)
            #if str(secondat)=="die": q2.put("die");break
            for i in self.sensors:
                current = b[i]
                del current[0:16]
                current += secondat[i]
                #q2.put(len(current))
                b[i] = current
                artree = PreprocessUtils.highpass(current)
                #q2.send("Highpass")
                win32 = numpy.hanning(512)
                artree = numpy.array(artree)
                stuff1 = win32 * artree
                stuff2 = PreprocessUtils.bin_power(stuff1, [1, 4, 8, 12, 30],
                                                   128)
                stuff4 = abs(20 * numpy.log(stuff2))
                stuff5 = tuple(stuff4[0])
                j[i].append(stuff5)
                #time.sleep(16/128)
            #if len(j["FC5"])==st:
            q2.send(j)
            for i in j.keys():
                j[i] = []
 def do_hanning_wndow(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.basic_window(self.data_dict[item])
Exemple #14
0
 def do_bin_power(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.bin_power(
             self.data_dict[item], [1, 4, 7, 13, 30], 128)
Exemple #15
0
 def do_hanning_wndow(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.basic_window(
             self.data_dict[item])
Exemple #16
0
 def do_high_pass(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.butter_highpass_filter(
             self.data_dict[item], 0.16, 128, 5)
 def do_bin_power(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.bin_power(self.data_dict[item], [1, 4, 7, 13, 30], 128)
 def do_high_pass(self):
     for item in self.data_dict.keys():
         self.data_dict[item] = PreprocessUtils.butter_highpass_filter(self.data_dict[item], 0.16, 128, 5)