aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorPiotr Krysik <ptrkrysik@gmail.com>2016-02-27 17:45:18 +0100
committerPiotr Krysik <ptrkrysik@gmail.com>2016-02-27 17:45:18 +0100
commit969c0ff52f8705298f35896a2cd19a3c826c19e9 (patch)
tree8b85f83154a070bd7e8ee11410f3657a7d18f6fc /apps
parent8c0f6fa539409dc59d72227deced96adce5b48b1 (diff)
Changes and improvements of options in the grgsm_channelize.py
- replaced xlat_fir_filter with rotator and pfb arbitrary resampler, - renamed some options, - added new options
Diffstat (limited to 'apps')
-rwxr-xr-xapps/helpers/grgsm_channelize.py93
1 files changed, 54 insertions, 39 deletions
diff --git a/apps/helpers/grgsm_channelize.py b/apps/helpers/grgsm_channelize.py
index 4098b7b..04b1633 100755
--- a/apps/helpers/grgsm_channelize.py
+++ b/apps/helpers/grgsm_channelize.py
@@ -37,11 +37,13 @@ from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from argparse import ArgumentParser, ArgumentTypeError, RawDescriptionHelpFormatter
import grgsm.arfcn as arfcn
+from gnuradio.filter import pfb
+import math
import os
EXTRA_HELP = """
Example usage:
-gsm_channelize.py -f my_wideband_capture.cfile -c 925.2e6 990 991 992 993 994 995 1019 1020 1021 1022 1023
+grgsm_channelize.py -f my_wideband_capture.cfile -c 925.2e6 990 991 992 993 994 995 1019 1020 1021 1022 1023
The above example will channelize my_wideband_capture.cfile, in this case a cfile captured at
925.2 MHz centered (ARFCN 975) and 20 Msps. As a result, 12 files will be generated for
@@ -61,31 +63,34 @@ def gsm_band(value):
else:
raise ArgumentTypeError("invalid GSM band: {0}. Possible choices are: {1}".format(value, choices))
-class gsm_channelize(gr.top_block):
- def __init__(self, channels, decim, ch_width, ch_twidth, fc, band, samp_rate, path):
- gr.top_block.__init__(self, "gsm_channelize")
+class grgsm_channelize(gr.top_block):
+ def __init__(self, channels, resamp_rate, fc, band, samp_rate, input_file, dest_dir, data_type="complex"):
+ gr.top_block.__init__(self, "grgsm_channelize")
##################################################
# Parameters
##################################################
self.channels = channels
- self.decim = decim
- self.ch_width = ch_width
- self.ch_twidth = ch_twidth
+ self.resamp_rate = resamp_rate
self.fc = fc
self.band = band
self.samp_rate = samp_rate
- self.blocks_fir_filters = {}
+ self.blocks_resamplers = {}
+ self.blocks_rotators = {}
self.blocks_file_sinks = {}
-
+
##################################################
# Blocks and connections
##################################################
- self.blocks_file_source = blocks.file_source(gr.sizeof_gr_complex, path, False)
+ self.source = None
+ if data_type == "ishort":
+ self.blocks_file_source = blocks.file_source(gr.sizeof_short, input_file, False)
+ self.source = blocks.interleaved_short_to_complex(False, False)
+ self.connect((self.blocks_file_source, 0), (self.source, 0))
+ elif data_type == "complex":
+ self.source = blocks.file_source(gr.sizeof_gr_complex, input_file, False)
- c0_arfcn = arfcn.downlink2arfcn(fc, band)
- self.channels.insert(0, c0_arfcn)
- print("Extracting channels %s, given that the center frequency is at ARFCN %d (%s)" % (str(channels), c0_arfcn, eng_notation.num_to_str(fc)))
+ print("Extracting channels %s, given that the center frequency is at %s" % (str(channels), eng_notation.num_to_str(fc)))
for channel in channels:
channel_freq = arfcn.arfcn2downlink(channel, band)
@@ -93,58 +98,68 @@ class gsm_channelize(gr.top_block):
print("Warning: invalid ARFCN %d for band %s" % (channel, band))
continue
freq_diff = channel_freq - fc
- print("ARFCN %d is at C0 %+d KHz" % (channel, int(freq_diff / 1000.0)))
+ print("ARFCN %d is at fc %+d KHz" % (channel, int(freq_diff / 1000.0)))
- self.blocks_fir_filters[channel] = filter.freq_xlating_fir_filter_ccc(decim, (firdes.low_pass(1, samp_rate, ch_width, ch_twidth)), freq_diff, samp_rate)
- self.connect((self.blocks_file_source, 0), (self.blocks_fir_filters[channel], 0))
+ self.blocks_resamplers[channel] = pfb.arb_resampler_ccf( resamp_rate, taps=None, flt_size=32)
+ self.blocks_rotators[channel] = blocks.rotator_cc(-2*math.pi*(freq_diff)/samp_rate)
+ self.connect( (self.source, 0), (self.blocks_rotators[channel], 0) )
+ self.connect( (self.blocks_rotators[channel], 0), (self.blocks_resamplers[channel], 0) )
- self.blocks_file_sinks[channel] = blocks.file_sink(gr.sizeof_gr_complex, "./gsm_channelizer/out_" + str(channel) + ".cfile", False)
+ self.blocks_file_sinks[channel] = blocks.file_sink(gr.sizeof_gr_complex, dest_dir+"/out_" + str(channel) + ".cfile", False)
self.blocks_file_sinks[channel].set_unbuffered(False)
- self.connect((self.blocks_fir_filters[channel], 0), (self.blocks_file_sinks[channel], 0))
+ self.connect((self.blocks_resamplers[channel], 0), (self.blocks_file_sinks[channel], 0))
if __name__ == '__main__':
- parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, description='Split wideband a GSM capture into seperate files per ARFCN.', epilog=EXTRA_HELP)
+ parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, description='Split wideband a GSM capture into seperate files per ARFCN.', add_help=True, epilog=EXTRA_HELP)
parser.add_argument(dest="channel", type=int, nargs='+',
help="List of ARFCNs")
- parser.add_argument("-w", "--width", dest="width", type=eng_float, default=eng_notation.num_to_str(200000),
- help="Channel lowpass width [default=%(default)s]")
- parser.add_argument("-t", "--transition-width", dest="twidth", type=eng_float, default=eng_notation.num_to_str(50000),
- help="Channel lowpass transition width [default=%(default)s]")
parser.add_argument("-s", "--samp-rate", dest="samp_rate", type=eng_float, default=eng_notation.num_to_str(2e7),
help="Sample rate of the wideband capture file [default=%(default)s]")
+ parser.add_argument("-f", "--fc", dest="fc", type=eng_float, default=eng_notation.num_to_str(935e6), required=True,
+ help="Carrier frequency in Hz [default=%(default)s]")
+ parser.add_argument("-b", "--band", dest="band", type=gsm_band, default='E-GSM',
+ help="GSM band [default=%(default)s]") #TODO: add automatic discovery based on fc
parser.add_argument("-o", "--out-samp-rate", dest="out_samp_rate", type=eng_float, default=eng_notation.num_to_str(1e6),
help="Sample rate of the output capture files [default=%(default)s]")
- parser.add_argument("-b", "--band", dest="band", type=gsm_band, default='E-GSM',
- help="GSM band [default=%(default)s]")
- parser.add_argument("-f", "--cfile", dest="path", type=str, required=True,
+ parser.add_argument("-i", "--input_file", dest="input_file", type=str, required=True,
help="Path to wideband GSM capture file")
- parser.add_argument("-c", "--C0", dest="fc", type=eng_float, default=eng_notation.num_to_str(925.2e6), required=True,
- help="C0 (BCCH) channel frequency in Hz [default=%(default)s]")
+ parser.add_argument("-t", "--data_type", dest="data_type", type=str, choices=["complex","ishort"], default="complex",
+ help="Type of the input file [default=%(default)s]")
+ parser.add_argument("-d", "--dest_dir", dest="dest_dir", type=str,
+ help="Destination directory - if not given defaults to input file name without extension")
+
args = parser.parse_args()
+
+ if not os.path.exists(args.input_file):
+ raise IOError(args.input_file + " does not exist")
+
+ input_filename, _ = os.path.splitext(os.path.basename(args.input_file))
- if not os.path.exists("./gsm_channelizer"):
- os.makedirs("./gsm_channelizer")
+ if args.dest_dir is None:
+ args.dest_dir = input_filename
+
+ if not os.path.exists("./"+args.dest_dir):
+ os.makedirs("./"+args.dest_dir)
- if not os.path.exists(args.path):
- raise IOError(args.path + " does not exist")
if args.samp_rate % args.out_samp_rate != 0:
raise Exception("Input sample rate should be multiple of output sample rate in order to get integer decimation.")
- decim = int(args.samp_rate / args.out_samp_rate)
+ resamp_rate = args.out_samp_rate / args.samp_rate
print("Input sample rate: " + eng_notation.num_to_str(args.samp_rate))
print("Output sample rate: " + eng_notation.num_to_str(args.out_samp_rate))
- print("==> using decimation of " + str(decim))
+ print("==> using resample rate of " + str(resamp_rate))
- tb = gsm_channelize(channels=args.channel,
- decim=decim,
- ch_width=args.width,
- ch_twidth=args.twidth,
+ tb = grgsm_channelize(channels=args.channel,
+ resamp_rate=resamp_rate,
fc=args.fc,
band=args.band,
samp_rate=args.samp_rate,
- path=args.path)
+ input_file=args.input_file,
+ dest_dir=args.dest_dir,
+ data_type=args.data_type
+ )
tb.start()
tb.wait()
print("Done!")