2014-08-31 91 views
2

我已经尝试打开用于分析的.cfile文件(通过RTL-SDR捕获的数据 )的流程图进行分析。我从 下载的文件链接http://sdr.osmocom.org/trac/attachment/wiki/rtl-sd ....bin到.c文件流程图GRC 3.7.2.1

但是,我无法让它在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: 

回答

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用户界面也是一个很好的练习。

+0

顺便提一句,流程图看起来像是可以用python和numpy写得很平常的东西,但是我们不会去玩gnuradio伴侣GUI。 – Paul 2014-10-14 03:38:08

+0

我有一个gqrx问题,使用流图的capture.cfile输出和rtl_sdr记录的capture.raw。来自gqrx的解调音频非常慢。其他人也报道了这一点。解决方案是在gqrx“sample_rate”框中以及file =,rate =字符串中设置采样率。显然,file =,rate = gqrx字符串中的采样率被忽略,采样率框为空的默认值可能为96k。 – Paul 2014-10-14 04:49:21

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); 
    } 
}