Python GRC 3.7.2.1的.bin到.cf文件流程图

Python GRC 3.7.2.1的.bin到.cf文件流程图,python,ubuntu,gnuradio,Python,Ubuntu,Gnuradio,我已尝试打开流图以转换.bin文件(数据) 通过RTL-SDR捕获)到.cfile进行分析。我从网上下载了这个文件 链接 但是,我无法使其在GRC 3.7.2.1上工作。当我尝试打开该文件时,会收到一长串错误消息(如下所示) 我正在使用Ubuntu v14.04.1 如果有人能帮助我解决这个问题,或者有其他方法将.bin文件转换为.cfile(python源代码?),我将不胜感激 ======================================================= >

我已尝试打开流图以转换.bin文件(数据) 通过RTL-SDR捕获)到.cfile进行分析。我从网上下载了这个文件 链接

但是,我无法使其在GRC 3.7.2.1上工作。当我尝试打开该文件时,会收到一长串错误消息(如下所示)

我正在使用Ubuntu v14.04.1

如果有人能帮助我解决这个问题,或者有其他方法将.bin文件转换为.cfile(python源代码?),我将不胜感激

=======================================================
>
显示:“
正在加载:“/home/zorro/Downloads/rtl2832 cfile.grc”
错误:
/home/zorro/Downloads/rtl2832 cfile.grc:2:0:错误:有效:DTD\u未知\u元素:
没有html元素的声明
/home/zorro/Downloads/rtl2832 cfile.grc:2:0:错误:有效:DTD_未知_属性:
元素html的属性xmlns没有声明
/home/zorro/Downloads/rtl2832 cfile.grc:9:0:ERROR:VALID:DTD\u UNKNOWN\u ELEM:
元素头没有声明
/home/zorro/Downloads/rtl2832 cfile.grc:10:0:ERROR:VALID:DTD\u UNKNOWN\u ELEM:

您看到的错误的原因是您的链接不正确-它被截断并指向HTML页面,而不是GRC文件。错误来自GRC试图将HTML解释为GRC XML。正确的下载链接是:

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


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

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

缺少的是确切的类型。它在里面。从中我们了解到,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);
  } 
}
#包括
#包括
#包括
//rtlsdr至gqrx版权所有2014 Paul Brewer KI6CQ
//许可证:CC BY-SA 3.0或GNU GPL 3.0
//IQ文件转换器
//从rtl_sdr记录格式——交错无符号字符
//到gqrx/gnuradio.cfile播放格式——complex64
void main(int argc,char*argv[])
{
int字节1,字节2;//int——不是无符号字符——参见fgetc手册页
浮点数复合fc;
常量大小\u t fc\u大小=大小(fc);
文件*infile,*outfile;
常量浮动比例=1.0/128.0;
常量char*infilename=argv[1];
const char*outfilename=argv[2];

如果(argcincidential,流程图看起来像是可以用python和numpy轻松编写的东西,但那样我们就无法使用gnuradio的伴奏GUI了。我在使用带有rtl_sdr录制的capture.raw的流程图的capture.cfile输出时遇到了gqrx问题。gqrx的解调音频非常慢。其他人报告说也是。解决方案是在gqrx“sample_rate”框以及文件=,rate=string中设置采样率。显然,文件=,rate=gqrx字符串中的采样率被忽略,采样率框为空的默认值可能是96k。
#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);
  } 
}