Skip to content
Snippets Groups Projects
Commit 9cceeb92 authored by Daniel Meißner's avatar Daniel Meißner Committed by Daniel Meißner
Browse files

added script to count zeros in enocean dumps via energy based signaldetection

parent 0cff140f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
##################################################
# GNU Radio Python Flow Graph
# Title: Top Block
# Generated: Fri Jan 22 17:58:53 2016
##################################################
import time
import struct
import array
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import numpy as np
class top_block(gr.top_block):
def __init__(self):
gr.top_block.__init__(self, "Top Block")
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 2e6
self.freq = freq = 868e6
##################################################
# Message queues (added by grcconvert)
##################################################
self.msgq_out = blocks_message_sink_0_msgq_out = gr.msg_queue(0)
##################################################
# Blocks
##################################################
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, 10*samp_rate,True)
self.blocks_threshold_ff_0 = blocks.threshold_ff(0.001, 0.001, 0)
self.blocks_message_sink_0 = blocks.message_sink(gr.sizeof_float*1, blocks_message_sink_0_msgq_out, False)
self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/home/meise/tmp/iq_dumps/enocean/868_2m_enocean.iq", False)
self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
##################################################
# Connections
##################################################
self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.blocks_threshold_ff_0, 0))
self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))
# removed by grcconvert: # self.connect((self.blocks_message_sink_0, 'msg'), (self, 0))
self.connect((self.blocks_threshold_ff_0, 0), (self.blocks_message_sink_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.blocks_throttle_0.set_sample_rate(self.samp_rate)
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = freq
def main(top_block_cls=top_block, options=None):
tb = top_block_cls()
tb.start()
data = np.memmap(open("/home/meise/tmp/iq_dumps/enocean/868_2m_enocean.iq"), mode="r", dtype=np.complex64)
samples_in_file = len(data)
print("sum of all samples: %s\n" % samples_in_file)
count_zero = 0
count_one = 0
samples_sum = 0
while True:
# pull from message queue
msg = tb.msgq_out.delete_head()
msg_string = msg.to_string()
# # extract floats from msg string
# # it is slow. very slow! :/
# for i in range(0,len(sample),4):
# # unpack sample to have a tuples
# unpacked = struct.unpack_from('f', sample[i:i+4])
# samples.append(unpacked[0])
# if len(unpacked) != 1:
# print("unpacked length: %s" % (len(unpacked)))
# convert string with floats into an numpy array
samples = np.fromstring(msg_string, dtype='float32')
# do some counting
count_one += np.count_nonzero(samples)
count_zero += np.count_nonzero(samples != 1.0)
samples_sum += len(samples)
if samples_sum == samples_in_file:
break
print("%s of %s sample" % (samples_sum, samples_in_file))
print("one: %s" % count_one)
print("zero: %s" % count_zero)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment