信号位恢复

时间:2017-11-18 20:08:01

标签: gnuradio-companion

我是使用GRC的新手。我正在尝试解码来自fsk设备的数据。我用rtl_433 -a -t(I / Q 2通道uint8)抓取数据,消除噪声,正交解调,低通滤波器,居中波和二进制切片。所以我明白了: enter image description here

从这里开始如何获得位转换/数据包?我也尝试过时钟恢复但没有成功(获得的数据与图形不一致。

这里是我的grc流程(还有时钟恢复变量) enter image description here

P.S。如何在第一个“位”之前剪切抓取的数据?这里我的输出Demod vs Binary切片。如果我导出二进制,我得到很多0(由信号之前的长行引起)。等等......

enter image description here

由于

1 个答案:

答案 0 :(得分:0)

我已经制作了一个python脚本来获取数据。 它编写了Bad and Fast但它有效:

import os.path
import string
import sys
import math

def print_buf(counter, buf):
    buf2 = [('%02x' % ord(i)) for i in buf]
    print '{0}: {1:<39}  {2}'.format(('%07x' % (counter * 16)),
        ' '.join([''.join(buf2[i:i + 2]) for i in range(0, len(buf2), 2)]),
        ''.join([c if c in string.printable[:-5] else '.' for c in buf]))

def process(file_path):
    data = ""
    with open(file_path, 'r') as f:
        counter = 0
        firstBit = 0
        while True:
            buf = f.read(16)
            if not buf:
                break
            if buf.encode('hex') == "00000000000000000000000000000000":
                #print "No data"
                if firstBit == 1:
                    #print "0Data"
                    data = data + buf.encode('hex')
            else:
                firstBit = 1
                #print "1Data"
                data = data + buf.encode('hex')
            #print counter
            #print buf.encode('hex')
            #work_data(counter,buf)
            # print_buf(counter, buf)
            counter += 1
    clean_data(data)

def clean_data(data):
    data = data.replace("00","0")
    data = data.replace("01","1")
    data_start = data.find("1")
    data = data[data_start:]
    data_stop = data.rfind("1")
    data = data[:data_stop+1]
    try:
        bit_size(data)
    except Exception, e:
        os.remove(sys.argv[2])
        print "Errore, File Rimosso", sys.argv[2]
    #print data

def bit_size(data):
    #Set one 1 bit max length (evaluated by setting var to an high value and get result)
    var1 = 30
    #Set one 0 bit max length (evaluated by setting var to an high value and get result)
    var2 = 30
    #Get timing from preamble, on eval set it to an high value (best to all file)
    var3 = 10 
    output=""
    flag1 = ""
    flag0 = ""
    avg1 = 0
    avg0 = 0
    min0 = 100
    max0 = 0
    min1 = 100
    max1 = 0
    count1 = 0
    count0 = 0
    sizer = data
    count3 = 0
    count4=0
    count5=0
    while len(sizer) > 1 and count3 <=var3:
        #print len(sizer)
        if sizer[:1] == "1":
           flag1 = sizer.find("0")
           #print "Size 1 " , flag1
           sizer = sizer[flag1:]
           if flag1 < var1 and flag1 > 0:
              print "Size 1 ", flag1
              avg1 += flag1
              count1 +=1
              count3 += 1
              count4 +=1
              if flag1 > max1:
                 max1 = flag1
              if flag1 < min1:
                 min1 = flag1
        else:
           flag0 = sizer.find("1")
           sizer = sizer[flag0:]
           #print "Size 0 " , flag0
           if flag0 < var2 and flag0 >0:
              print "Size 0 ", flag0
              avg0 += flag0
              count0 += 1
              count3 += 1
              count5 += 1
              if flag0 > max0:
                 max0 = flag0
              if flag0 < min0:
                 min0 = flag0

    #print avg0, avg1, count0, count1
    avg0=avg0/count5
    avg1=avg1/count4
    mod0=math.fmod(avg0,count5)
    mod1=math.fmod(avg1,count4)
    print "0--> Media:" , avg0, "Max:" , max0, "Min:",min0, "Resto:", mod0
    print "1--> Media:" , avg1, "Max:" , max1, "Min:",min1, "Resto:", mod1
    sizer = data
    Smax1=0
    Smin1=0
    Savg1=0
    Smax0=0
    Smin0=0
    Savg0=0
    Cavg0=0
    Cavg1=0
    Scor0=0
    Scor1=0
    while len(sizer) > 1:
        if sizer[:1] == "1":
           flag1 = sizer.find("0")
           sizer = sizer[flag1:]
           Nmax1 = flag1 / max1
           Nmin1 = flag1 / min1
           Navg1 = flag1 / avg1
           Smax1+=Nmax1
           Smin1+=Nmin1
           Savg1+=Navg1
           Mmax1=math.fmod(flag1,max1)
           Mmin1=math.fmod(flag1,min1)
           Mavg1=math.fmod(flag1,avg1)
           if Mavg1 > 5:
              Cavg1 = Navg1 + 1
           else:
              Cavg1 = Navg1
           Scor1 += Cavg1
           output += "1" * Cavg1
           #print "1--> Size:", flag1, "EstByMin:", Nmin1, "EstByMax:", Nmax1, "EstByAvg:", Navg1, "RestoDaMedia:", Mavg1, "RestoDaMin:", Mmin1, "RestoDaMax:",Mmax1, "Correzione:", Cavg1
        else:
           flag0 = sizer.find("1")
           sizer = sizer[flag0:]
           #print "Size 0 " , flag0
           if flag0 > 0:
                Nmax0 = flag0 / max0
                Nmin0 = flag0 / min0
                Navg0 = flag0 / avg0
                Smax0+=Nmax0
            Smin0+=Nmin0
            Savg0+=Navg0
            Mmax0=math.fmod(flag0,max0)
            Mmin0=math.fmod(flag0,min0)
            Mavg0=math.fmod(flag0,avg0)
            if Mavg0 > 5:
                   Cavg0 = Navg0 + 1
            else:
                   Cavg0 = Navg0
                Scor0 += Cavg0
                output += "0" * Cavg0
                #print "0--> Size:", flag0, "EstByMin:", Nmin0, "EstByMax:", Nmax0, "EstByAvg:", Navg0, "RestoDaMedia:", Mavg0, "RestoDaMin:", Mmin0, "RestoDaMax:",Mmax0, "Correzione:", Cavg0
    #print "1--> TotByMin:" , Smin1, "TotByMax:",Smax1, "TotByAvg:",Savg1,"TotByCorr:", Scor1
    #print "0--> TotByMin:" , Smin0, "TotByMax:",Smax0, "TotByAvg:",Savg0,"TotByCorr:", Scor0
    #print "---> TotByMin:" , Smin0+Smin1, "TotByMax:" ,Smax1+Smax0, "TotByAvg:", Savg1+Savg0, "TotByCorr:", Scor0+Scor1
    #print output
    data_rec(output)

def data_rec(input):
    byte=""
    count = 1
    precount = 0
    predebug = ""
    debug = input
    while input[:1] == "1":
       input = input[1:]
    while input[:2] == "01":
       precount+=2
       predebug += "01"
       input= input[2:]
    ##print "--------------------------------------"
    ##if precount > 0:
        ##print "Preamble --> OK", predebug, " Count:" , precount
    ##else:
        ##print "Preamble? -->", debug
        ##os.remove(sys.argv[2])
    preamble=input
    #print preamble
    preamble = ' '.join(preamble[i:i+8] for i in range(0, len(preamble), 8)) 
    #print preamble
    output = ''.join(hex(int(a, 2))[2:] for a in preamble.split())
    #print output
    data = input[34:]
    data = ' '.join(data[i:i+8] for i in range(0, len(data), 8)) 
    #print data
    data = ''.join(hex(int(a, 2))[2:] for a in data.split())
    #print data
    for a in data:
         byte+=a
         if math.fmod(count,2) == 0:
            byte+=" "
         count+=1
    print " "
    ##print byte
    ##print "ByteCount:" , count
    print preamble
    ##print "File:" , sys.argv[2]
    ##print "--------------------------------------------------"
if __name__ == '__main__':
    if not os.path.exists(sys.argv[1]):
        print >> (sys.stderr, "The file doesn't exist.")
        sys.exit(1)
    process(sys.argv[1])