【问题标题】:.bin to .cfile flowgraph for GRC 3.7.2.1GRC 3.7.2.1 的 .bin 到 .cfile 流程图
【发布时间】:2014-10-24 15:03:19
【问题描述】:

我已尝试打开用于转换 .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:

【问题讨论】:

    标签: python ubuntu gnuradio


    【解决方案1】:

    您看到错误的原因是您的链接不正确——它被截断并指向 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 用户界面也是一个很好的练习。

    【讨论】:

    • 顺便说一句,流程图看起来可以用 python 和 numpy 简单地编写,但是我们无法使用 gnuradio 配套 GUI。
    • 我在使用流程图中的 capture.cfile 输出和 rtl_sdr 记录的 capture.raw 时遇到了 gqrx 问题。来自 gqrx 的解调音频非常慢。其他人也报告了这一点。解决方案是在 gqrx "sample_rate" 框中以及 file=,rate= 字符串中设置采样率。显然,file=,rate= gqrx 字符串中的采样率被忽略了,采样率框为空白的默认值可能是 96k。
    【解决方案2】:

    如果您查看上面@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 并检查 @987654324 @,但出于爱好目的,它按原样工作。

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

    【讨论】:

      猜你喜欢
      • 2019-08-17
      • 2019-11-17
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 2011-01-20
      相关资源
      最近更新 更多