我曾尝试打开用于转换.bin文件(通过RTL-SDR捕获的数据)到.c文件的stream程图进行分析。 我从链接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:
你看到的错误的原因是你的链接是坏的 – 它被截断,并指向一个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用户界面的一个很好的练习。
如果你看一下上面@Kevin Reid发布的流程图,你可以看到输入数据减去127,乘以0.008,并将对转换为复数。
缺少的是确切的类型。 这是在GNU电台的常见问题 。 从那里我们知道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); } }