if sample_rate == None: print >> sys.stderr, "Sample rate missing!" exit(1) if center == None: print >> sys.stderr, "Need to specify center frequency!" exit(1) if len(remainder) == 0: file_name = "/dev/stdin" basename = "stdin" else: file_name = remainder[0] basename = filename = re.sub('\.[^.]*$', '', file_name) signal = iq.read(file_name) cad = cut_and_downmix.CutAndDownmix(center=center, sample_rate=sample_rate, symbols_per_second=symbols_per_second, preamble_length=preamble_length, search_depth=search_depth, verbose=verbose, search_window=search_window) d = demod.Demod(sample_rate=sample_rate, verbose=verbose) temp_signal, freq, _ = cad.cut_and_downmix(signal=signal, search_offset=search_offset, direction=direction) dataarray, data, access_ok, lead_out_ok, confidence, level, nsymbols, final_offset = d.demod(
def find_start(signal, sample_rate=2000000): input_low_pass = scipy.signal.firwin(13, 1000. / sample_rate) count = 100e-3 * sample_rate signal_mag = numpy.abs(signal) signal_mag_filtered = scipy.signal.fftconvolve(signal_mag, input_low_pass, mode='same') level = numpy.average(signal_mag_filtered) low_count = 0 for i in xrange(len(signal_mag)): if signal_mag_filtered[i] < level / 1.2: low_count += 1 else: #if low_count > 100: if low_count > sample_rate * 0.5e-3: print "start at", i return i low_count = 0 raise Exception("No start found") return 0 if __name__ == "__main__": signal = iq.read(sys.argv[1]) print find_start(signal)
frequency_offset = float(arg) elif opt in ('-v', '--verbose'): verbose = True elif opt in ('-d', '--decimation'): decimation = int(arg) print "deci:",decimation if sample_rate == None: print >> sys.stderr, "Sample rate missing!" exit(1) if center == None: print >> sys.stderr, "Need to specify center frequency!" exit(1) if len(remainder)==0: file_name = "/dev/stdin" basename="stdin" else: file_name = remainder[0] basename= filename= re.sub('\.[^.]*$','',file_name) signal = iq.read(file_name) cad = CutAndDownmix(center=center, input_sample_rate=sample_rate, symbols_per_second=symbols_per_second, search_depth=search_depth, verbose=verbose, decimation=decimation) signal, freq = cad.cut_and_downmix(signal=signal, search_offset=search_offset, search_window=search_window, frequency_offset=frequency_offset) iq.write("%s-f%010d.cut" % (os.path.basename(basename), freq), signal) print "output=","%s-f%10d.cut" % (os.path.basename(basename), freq)