2014-08-31 87 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); 
    } 
}