Skip to content

Commit

Permalink
Merge pull request #731 from anarkiwi/dco
Browse files Browse the repository at this point in the history
Make dB range configurable, add DC filter option.
  • Loading branch information
anarkiwi authored Jun 18, 2023
2 parents cf1dd36 + 6d07d2a commit 54911dc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
40 changes: 26 additions & 14 deletions gamutrf/grscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path

try:
from gnuradio import filter # pytype: disable=import-error
from gnuradio import blocks # pytype: disable=import-error
from gnuradio import fft # pytype: disable=import-error
from gnuradio import gr # pytype: disable=import-error
Expand Down Expand Up @@ -48,6 +49,10 @@ def __init__(
tuning_ranges="",
scaling="spectrum",
description="",
dc_block_len=0,
dc_block_long=False,
db_clamp_floor=-200,
db_clamp_ceil=50,
iqtlabs=None,
wavelearner=None,
):
Expand Down Expand Up @@ -77,7 +82,9 @@ def __init__(
sdrargs=sdrargs,
)

fft_blocks, fft_roll = self.get_fft_blocks(fft_size, sdr)
fft_blocks, fft_roll = self.get_fft_blocks(
fft_size, sdr, dc_block_len, dc_block_long
)
self.fft_blocks = fft_blocks + self.get_db_blocks(fft_size, samp_rate, scaling)
self.fft_to_inference_block = self.fft_blocks[-1]

Expand Down Expand Up @@ -123,8 +130,8 @@ def __init__(
tune_step_fft,
skip_tune_step,
fft_roll,
-200,
50,
db_clamp_floor,
db_clamp_ceil,
sample_dir,
write_samples,
bucket_range,
Expand Down Expand Up @@ -251,10 +258,15 @@ def get_db_blocks(self, fft_size, samp_rate, scaling):
def get_window(self, fft_size):
return window.hann(fft_size)

def get_fft_blocks(self, fft_size, sdr):
def get_fft_blocks(self, fft_size, sdr, dc_block_len, dc_block_long):
fft_blocks = []
fft_roll = False
if dc_block_len:
fft_blocks.append(filter.dc_blocker_cc(dc_block_len, dc_block_long))
if self.wavelearner:
fft_batch_size = 256
return (
fft_roll = True
fft_blocks.extend(
[
blocks.stream_to_vector(
gr.sizeof_gr_complex, fft_batch_size * fft_size
Expand All @@ -269,16 +281,16 @@ def get_fft_blocks(self, fft_size, sdr):
blocks.vector_to_stream(
gr.sizeof_gr_complex * fft_size, fft_batch_size
),
],
True,
]
)
return (
[
blocks.stream_to_vector(gr.sizeof_gr_complex, fft_size),
fft.fft_vcc(fft_size, True, self.get_window(fft_size), True, 1),
],
False,
)
else:
fft_blocks.extend(
[
blocks.stream_to_vector(gr.sizeof_gr_complex, fft_size),
fft.fft_vcc(fft_size, True, self.get_window(fft_size), True, 1),
]
)
return (fft_blocks, fft_roll)

def start(self):
super().start()
Expand Down
31 changes: 31 additions & 0 deletions gamutrf/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,33 @@ def argument_parser():
default=0.85,
help="what proportion of FFT buckets to use",
)
parser.add_argument(
"--db_clamp_floor",
dest="db_clamp_floor",
type=float,
default=-200,
help="clamp dB output floor",
)
parser.add_argument(
"--db_clamp_ceil",
dest="db_clamp_ceil",
type=float,
default=50,
help="clamp dB output ceil",
)
parser.add_argument(
"--dc_block_len",
dest="dc_block_len",
type=int,
default=0,
help="if > 0, use dc_block_cc filter with length",
)
parser.add_argument(
"--dc_block_long",
dest="dc_block_long",
action="store_true",
help="Use dc_block_cc long form",
)
parser.add_argument(
"--inference_plan_file",
dest="inference_plan_file",
Expand Down Expand Up @@ -286,6 +313,10 @@ def run_loop(options, prom_vars, wavelearner):
sample_dir=handler.options.sample_dir,
write_samples=handler.options.write_samples,
bucket_range=handler.options.bucket_range,
db_clamp_floor=handler.options.db_clamp_floor,
db_clamp_ceil=handler.options.db_clamp_ceil,
dc_block_len=handler.options.dc_block_len,
dc_block_long=handler.options.dc_block_long,
inference_plan_file=handler.options.inference_plan_file,
inference_output_dir=handler.options.inference_output_dir,
inference_input_len=handler.options.inference_input_len,
Expand Down

0 comments on commit 54911dc

Please sign in to comment.