如果你看看上面@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\u sdr文件格式到gqrx IQ示例输入文件格式的转换,它似乎在内存中可以很好地工作。在
但请注意,此脚本只适用于输入和输出文件都可以放入内存的数据。对于大于系统内存1/5的输入文件(sdr记录很容易超过这个值),最好一次读取一个字节。在
我们可以通过循环一次读取1个字节的数据来避免内存占用,就像下面gnu C中的程序一样。这不是最干净的代码,我可能应该添加fclose并检查ferror,但出于爱好,它的工作原理是一样的。在
^{pr2}$