.bin到.cfile流程图,用于GRC 3.7.2.1

时间:2014-08-31 00:33:32

标签: python ubuntu gnuradio

我试过打开流图来转换.bin文件(数据 通过RTL-SDR捕获到.cfile进行分析。我从中下载了文件 链接http://sdr.osmocom.org/trac/attachment/wiki/rtl-sd ...

但是,我无法让它在GRC 3.7.2.1上运行。当我尝试打开文件时,我得到一长串错误消息(如下所示)。

我使用的是Ubuntu v14.04.1。

我真的很感激有任何帮助来解决这个或任何替代方法将.bin文件转换为.cfile(python源代码?)

=======================================================
 <<< Welcome to GNU Radio Companion 3.7.2.1 >>>

Showing: ""

Loading: "/home/zorro/Downloads/rtl2832-cfile.grc"
Error:
/home/zorro/Downloads/rtl2832-cfile.grc:2:0:ERROR:VALID:DTD_UNKNOWN_ELEM:
No declaration for element html
/home/zorro/Downloads/rtl2832-cfile.grc:2:0:ERROR:VALID:DTD_UNKNOWN_ATTRIBUTE:
No declaration for attribute xmlns of element html
/home/zorro/Downloads/rtl2832-cfile.grc:9:0:ERROR:VALID:DTD_UNKNOWN_ELEM:
No declaration for element head
/home/zorro/Downloads/rtl2832-cfile.grc:10:0:ERROR:VALID:DTD_UNKNOWN_ELEM:

2 个答案:

答案 0 :(得分:4)

您看到的错误原因是您的链接不正确 - 它被截断并指向HTML页面,而不是GRC文件。错误来自GRC尝试将HTML解释为GRC XML。下载的正确链接是:http://sdr.osmocom.org/trac/raw-attachment/wiki/rtl-sdr/rtl2832-cfile.grc

但请注意,该流程图是为GNU Radio 3.6构建的,由于内部重命名了许多块,因此无法在GNU Radio 3.7中使用。我建议使用提供的图片从头开始重建它。

  

由于此流程图中没有变量,您只需拖出块并设置参数,如图所示。这样做对于熟悉GNU Radio Companion用户界面也是一个很好的练习。

答案 1 :(得分:1)

如果您查看上面@Kevin Reid发布的流程图,您可以看到它接受输入数据,减去127,乘以0.008,并将对转换为复数。

缺少的是确切的类型。它位于the GNU Radio FAQ。从那里我们知道uchar是一个无符号字符(8位),复杂数据类型是python中的'complex64'。

如果在numpy中完成,作为内存中操作,它看起来像这样:

import numpy as np
import sys

(scriptName, inFileName, outFileName) = sys.argv;

ubytes = np.fromfile(inFileName, dtype='uint8', count=-1)

# we need an even number of bytes
# discard last byte if the count is odd

if len(ubytes)%2==1:
    ubytes = ubytes[0:-1]

print "read "+str(len(ubytes))+" bytes from "+inFileName

# scale the unsigned byte data to become a float in the interval 0.0 to 1.0

ufloats = 0.008*(ubytes.astype(float)-127.0)

ufloats.shape = (len(ubytes)/2, 2)

# turn the pairs of floats into complex numbers, needed by gqrx and other gnuradio software

IQ_data = (ufloats[:,0]+1j*ufloats[:,1]).astype('complex64')

IQ_data.tofile(outFileName)

我已经测试了从rtl_sdr文件格式到gqrx IQ样本输入文件格式的转换,它似乎可以在适合内存的内容中正常工作。

但请注意,此脚本仅适用于两个输入和输出文件都可以放入内存的数据。对于大于系统内存大约1/5的输入文件,sdr记录很容易超过,最好一次读取一个字节。

我们可以通过循环读取数据1字节来避免内存占用,就像gnu C中的以下程序一样。这不是最干净的代码,我应该添加fclose并检查ferror,但它可以用于业余爱好。

#include <complex.h>
#include <stdio.h>
#include <stdlib.h>

// rtlsdr-to-gqrx Copyright 2014 Paul Brewer KI6CQ
// License: CC BY-SA 3.0 or GNU GPL 3.0
// IQ file converter 
// from rtl_sdr recording format -- interleaved unsigned char
// to gqrx/gnuradio .cfile playback format -- complex64 

void main(int argc, char *argv[])
{
  int byte1, byte2;  // int -- not unsigned char -- see fgetc man page
  float _Complex fc;
  const size_t fc_size = sizeof(fc);
  FILE *infile,*outfile;
  const float scale = 1.0/128.0;
  const char *infilename = argv[1];
  const char *outfilename = argv[2];
  if (argc<3){
    printf("usage:  rtlsdr-to-gqrx infile outfile\n");
    exit(1);
  }
  // printf("in= %s out= %s \n", infilename, outfilename);
  infile=fopen(infilename,"rb");
  outfile=fopen(outfilename,"wb");
  if ((infile==NULL) || (outfile==NULL)){
    printf("Error opening files\n");
    exit(1);
  }
  while ((byte1=fgetc(infile)) != EOF){
    if ((byte2=fgetc(infile)) == EOF){
      exit(0);
    }
    fc = scale*(byte1-127) + I*scale*(byte2-127);
    fwrite(&fc,fc_size,1,outfile);
  } 
}