From 42fde01ca6704b0ab721e35a7225daadb6cbefc0 Mon Sep 17 00:00:00 2001 From: mleech Date: Sat, 7 Oct 2006 12:42:24 +0000 Subject: Added waterfall display, and SETI processing options to usrp_ra_receiver, which necessitated an RA-specific version of waterfallsink. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3735 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-radio-astronomy/src/python/Makefile.am | 3 +- gr-radio-astronomy/src/python/ra_waterfallsink.py | 510 ++++++++++++++++++++++ gr-radio-astronomy/src/python/usrp_ra_receiver.py | 155 ++++++- 3 files changed, 661 insertions(+), 7 deletions(-) create mode 100755 gr-radio-astronomy/src/python/ra_waterfallsink.py (limited to 'gr-radio-astronomy/src') diff --git a/gr-radio-astronomy/src/python/Makefile.am b/gr-radio-astronomy/src/python/Makefile.am index e06a2607c..bede7f6e2 100644 --- a/gr-radio-astronomy/src/python/Makefile.am +++ b/gr-radio-astronomy/src/python/Makefile.am @@ -49,7 +49,8 @@ ourpython_PYTHON = \ wxguipython_PYTHON = \ ra_stripchartsink.py \ - ra_fftsink.py + ra_fftsink.py \ + ra_waterfallsink.py # and here for applications you want installed in prefix/bin diff --git a/gr-radio-astronomy/src/python/ra_waterfallsink.py b/gr-radio-astronomy/src/python/ra_waterfallsink.py new file mode 100755 index 000000000..b6c63ac25 --- /dev/null +++ b/gr-radio-astronomy/src/python/ra_waterfallsink.py @@ -0,0 +1,510 @@ +#!/usr/bin/env python +# +# Copyright 2003,2004,2005 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gru, window +from gnuradio.wxgui import stdgui +import wx +import gnuradio.wxgui.plot as plot +import Numeric +import os +import threading +import math + +default_fftsink_size = (640,240) +default_fft_rate = gr.prefs().get_long('wxgui', 'fft_rate', 15) + +class ra_waterfallsink_base(object): + def __init__(self, input_is_real=False, baseband_freq=0, + sample_rate=1, fft_size=512, + fft_rate=default_fft_rate, + average=False, avg_alpha=None, title='', ofunc=None, xydfunc=None, scaling=100): + + # initialize common attributes + self.baseband_freq = baseband_freq + self.sample_rate = sample_rate + self.fft_size = fft_size + self.fft_rate = fft_rate + self.average = average + self.ofunc = ofunc + self.xydfunc = xydfunc + self.scaling = scaling + if avg_alpha is None: + self.avg_alpha = 2.0 / fft_rate + else: + self.avg_alpha = avg_alpha + self.title = title + self.input_is_real = input_is_real + self.msgq = gr.msg_queue(2) # queue up to 2 messages + + def set_average(self, average): + self.average = average + if average: + self.avg.set_taps(self.avg_alpha) + else: + self.avg.set_taps(1.0) + + def set_avg_alpha(self, avg_alpha): + self.avg_alpha = avg_alpha + + def set_baseband_freq(self, baseband_freq): + self.baseband_freq = baseband_freq + + def set_sample_rate(self, sample_rate): + self.sample_rate = sample_rate + self._set_n() + + def set_scaling(self,scaling): + self.scaling = scaling + return + + def _set_n(self): + self.one_in_n.set_n(max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) + +class ra_waterfallsink_f(gr.hier_block, ra_waterfallsink_base): + def __init__(self, fg, parent, baseband_freq=0, + y_per_div=10, ref_level=50, sample_rate=1, fft_size=512, + fft_rate=default_fft_rate, average=False, avg_alpha=None, + title='', scaling=100, size=default_fftsink_size, ofunc=None, xydfunc=None): + + ra_waterfallsink_base.__init__(self, input_is_real=True, baseband_freq=baseband_freq, + sample_rate=sample_rate, fft_size=fft_size, + fft_rate=fft_rate, + average=average, avg_alpha=avg_alpha, title=title, ofunc=ofunc, xydfunc=xydfunc, scaling=scaling) + + s2p = gr.serial_to_parallel(gr.sizeof_float, self.fft_size) + self.one_in_n = gr.keep_one_in_n(gr.sizeof_float * self.fft_size, + max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) + mywindow = window.blackmanharris(self.fft_size) + fft = gr.fft_vfc(self.fft_size, True, mywindow) + c2mag = gr.complex_to_mag(self.fft_size) + self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) + log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)) + sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) + + fg.connect (s2p, self.one_in_n, fft, c2mag, self.avg, log, sink) + gr.hier_block.__init__(self, fg, s2p, sink) + + self.win = ra_waterfall_window(self, parent, size=size) + self.set_average(self.average) + + +class ra_waterfallsink_c(gr.hier_block, ra_waterfallsink_base): + def __init__(self, fg, parent, baseband_freq=0, + y_per_div=10, ref_level=50, sample_rate=1, fft_size=512, + fft_rate=default_fft_rate, average=False, + avg_alpha=None, scaling=100, + title='', size=default_fftsink_size, ofunc=None, xydfunc=None): + + ra_waterfallsink_base.__init__(self, input_is_real=False, baseband_freq=baseband_freq, + sample_rate=sample_rate, fft_size=fft_size, + fft_rate=fft_rate, + average=average, + avg_alpha=avg_alpha, + title=title, ofunc=ofunc, + xydfunc=xydfunc, scaling=scaling) + + s2p = gr.serial_to_parallel(gr.sizeof_gr_complex, self.fft_size) + self.one_in_n = gr.keep_one_in_n(gr.sizeof_gr_complex * self.fft_size, + max(1, int(self.sample_rate/self.fft_size/self.fft_rate))) + + mywindow = window.blackmanharris(self.fft_size) + fft = gr.fft_vcc(self.fft_size, True, mywindow) + c2mag = gr.complex_to_mag(self.fft_size) + self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size) + log = gr.nlog10_ff(20, self.fft_size, -20*math.log10(self.fft_size)) + sink = gr.message_sink(gr.sizeof_float * self.fft_size, self.msgq, True) + + fg.connect(s2p, self.one_in_n, fft, c2mag, self.avg, log, sink) + gr.hier_block.__init__(self, fg, s2p, sink) + + self.win = ra_waterfall_window(self, parent, size=size) + self.set_average(self.average) + + +# ------------------------------------------------------------------------ + +myDATA_EVENT = wx.NewEventType() +EVT_DATA_EVENT = wx.PyEventBinder (myDATA_EVENT, 0) + + +class DataEvent(wx.PyEvent): + def __init__(self, data): + wx.PyEvent.__init__(self) + self.SetEventType (myDATA_EVENT) + self.data = data + + def Clone (self): + self.__class__ (self.GetId()) + + +class input_watcher (threading.Thread): + def __init__ (self, msgq, fft_size, event_receiver, **kwds): + threading.Thread.__init__ (self, **kwds) + self.setDaemon (1) + self.msgq = msgq + self.fft_size = fft_size + self.event_receiver = event_receiver + self.keep_running = True + self.start () + + def run (self): + while (self.keep_running): + msg = self.msgq.delete_head() # blocking read of message queue + itemsize = int(msg.arg1()) + nitems = int(msg.arg2()) + + s = msg.to_string() # get the body of the msg as a string + + # There may be more than one FFT frame in the message. + # If so, we take only the last one + if nitems > 1: + start = itemsize * (nitems - 1) + s = s[start:start+itemsize] + + complex_data = Numeric.fromstring (s, Numeric.Float32) + de = DataEvent (complex_data) + wx.PostEvent (self.event_receiver, de) + del de + + +class ra_waterfall_window (wx.Panel): + def __init__ (self, fftsink, parent, id = -1, + pos = wx.DefaultPosition, size = wx.DefaultSize, + style = wx.DEFAULT_FRAME_STYLE, name = ""): + wx.Panel.__init__(self, parent, id, pos, size, style, name) + + self.fftsink = fftsink + self.bm = wx.EmptyBitmap(self.fftsink.fft_size, 300, -1) + + self.scale_factor = self.fftsink.scaling + + dc1 = wx.MemoryDC() + dc1.SelectObject(self.bm) + dc1.Clear() + + self.pens = self.make_pens() + + wx.EVT_PAINT( self, self.OnPaint ) + wx.EVT_CLOSE (self, self.on_close_window) + EVT_DATA_EVENT (self, self.set_data) + + self.build_popup_menu() + + wx.EVT_CLOSE (self, self.on_close_window) + self.Bind(wx.EVT_RIGHT_UP, self.on_right_click) + + self.input_watcher = input_watcher(fftsink.msgq, fftsink.fft_size, self) + + + def on_close_window (self, event): + print "ra_waterfall_window: on_close_window" + self.keep_running = False + + def const_list(self,const,len): + return [const] * len + + def make_colormap(self): + r = [] + r.extend(self.const_list(0,96)) + r.extend(range(0,255,4)) + r.extend(self.const_list(255,64)) + r.extend(range(255,128,-4)) + + g = [] + g.extend(self.const_list(0,32)) + g.extend(range(0,255,4)) + g.extend(self.const_list(255,64)) + g.extend(range(255,0,-4)) + g.extend(self.const_list(0,32)) + + b = range(128,255,4) + b.extend(self.const_list(255,64)) + b.extend(range(255,0,-4)) + b.extend(self.const_list(0,96)) + return (r,g,b) + + def make_pens(self): + (r,g,b) = self.make_colormap() + pens = [] + for i in range(0,256): + colour = wx.Colour(r[i], g[i], b[i]) + pens.append( wx.Pen(colour, 2, wx.SOLID)) + return pens + + def OnPaint(self, event): + dc = wx.PaintDC(self) + self.DoDrawing(dc) + + def DoDrawing(self, dc=None): + if dc is None: + dc = wx.ClientDC(self) + dc.DrawBitmap(self.bm, 0, 0, False ) + + + def const_list(self,const,len): + a = [const] + for i in range(1,len): + a.append(const) + return a + + def make_colormap(self): + r = [] + r.extend(self.const_list(0,96)) + r.extend(range(0,255,4)) + r.extend(self.const_list(255,64)) + r.extend(range(255,128,-4)) + + g = [] + g.extend(self.const_list(0,32)) + g.extend(range(0,255,4)) + g.extend(self.const_list(255,64)) + g.extend(range(255,0,-4)) + g.extend(self.const_list(0,32)) + + b = range(128,255,4) + b.extend(self.const_list(255,64)) + b.extend(range(255,0,-4)) + b.extend(self.const_list(0,96)) + return (r,g,b) + + def set_data (self, evt): + dB = evt.data + L = len (dB) + + if (self.fftsink.ofunc != None): + self.fftsink.ofunc (evt.data, L) + + dc1 = wx.MemoryDC() + dc1.SelectObject(self.bm) + dc1.Blit(0,1,self.fftsink.fft_size,300,dc1,0,0,wx.COPY,False,-1,-1) + + x = max(abs(self.fftsink.sample_rate), abs(self.fftsink.baseband_freq)) + if x >= 1e9: + sf = 1e-9 + units = "GHz" + elif x >= 1e6: + sf = 1e-6 + units = "MHz" + else: + sf = 1e-3 + units = "kHz" + + + if self.fftsink.input_is_real: # only plot 1/2 the points + d_max = L/2 + p_width = 2 + else: + d_max = L/2 + p_width = 1 + + WATERFALL_WIDTH=1024 + scale_factor = self.scale_factor + x_positions = Numeric.zeros(WATERFALL_WIDTH, Numeric.Float64) + y_values = Numeric.zeros(WATERFALL_WIDTH, Numeric.Float64) + x_scale = L / WATERFALL_WIDTH + x_scale = int(x_scale) + if self.fftsink.input_is_real: # real fft + for x_pos in range(0, d_max): + value = int(dB[x_pos] * scale_factor) + value = min(255, max(0, value)) + idx = int(x_pos/x_scale) + idx = min(WATERFALL_WIDTH-1,idx) + x_positions[idx] = idx + y_values[idx] = y_values[idx] + value + #dc1.SetPen(self.pens[value]) + #dc1.DrawRectangle(x_pos*p_width, 0, p_width, 1) + else: # complex fft + for x_pos in range(0, d_max): # positive freqs + value = int(dB[x_pos] * scale_factor) + value = min(255, max(0, value)) + idx = int((x_pos+d_max)/x_scale) + idx = min(WATERFALL_WIDTH-1,idx) + x_positions[idx] = idx + y_values[idx] = y_values[idx] + value + #dc1.SetPen(self.pens[value]) + #dc1.DrawRectangle(x_pos*p_width + d_max, 0, p_width, 1) + for x_pos in range(0 , d_max): # negative freqs + value = int(dB[x_pos+d_max] * scale_factor) + value = min(255, max(0, value)) + idx = int((x_pos)/x_scale) + idx = min(WATERFALL_WIDTH-1,idx) + x_positions[idx] = idx + y_values[idx] = y_values[idx] + value + #dc1.SetPen(self.pens[value]) + #dc1.DrawRectangle(x_pos*p_width, 0, p_width, 1) + + for i in range(0,WATERFALL_WIDTH): + yv = y_values[i]/x_scale + yv = int(min(255,yv)) + dc1.SetPen(self.pens[yv]) + dc1.DrawRectangle(i*p_width, 0, p_width, 1) + + self.DoDrawing (None) + + def on_average(self, evt): + # print "on_average" + self.fftsink.set_average(evt.IsChecked()) + + def on_right_click(self, event): + menu = self.popup_menu + for id, pred in self.checkmarks.items(): + item = menu.FindItemById(id) + item.Check(pred()) + self.PopupMenu(menu, event.GetPosition()) + + def on_scaling(self, evt): + Id = evt.GetId() + if Id == self.id_scaling_100: + self.fftsink.set_scaling(100) + elif Id == self.id_scaling_150: + self.fftsink.set_scaling(150) + elif Id == self.id_scaling_200: + self.fftsink.set_scaling(200) + elif Id == self.id_scaling_250: + self.fftsink.set_scaling(250) + elif Id == self.id_scaling_300: + self.fftsink.set_scaling(300) + + def build_popup_menu(self): + self.id_scaling_100 = wx.NewId() + self.id_scaling_150 = wx.NewId() + self.id_scaling_200 = wx.NewId() + self.id_scaling_250 = wx.NewId() + self.id_scaling_300 = wx.NewId() + self.id_average = wx.NewId() + + self.Bind(wx.EVT_MENU, self.on_average, id=self.id_average) + self.Bind(wx.EVT_MENU, self.on_scaling, id=self.id_scaling_100) + self.Bind(wx.EVT_MENU, self.on_scaling, id=self.id_scaling_150) + self.Bind(wx.EVT_MENU, self.on_scaling, id=self.id_scaling_200) + self.Bind(wx.EVT_MENU, self.on_scaling, id=self.id_scaling_250) + self.Bind(wx.EVT_MENU, self.on_scaling, id=self.id_scaling_300) + + + # make a menu + menu = wx.Menu() + self.popup_menu = menu + menu.AppendCheckItem(self.id_average, "Average") + menu.AppendCheckItem(self.id_scaling_100, "100 scale factor") + menu.AppendCheckItem(self.id_scaling_150, "150 scale factor") + menu.AppendCheckItem(self.id_scaling_200, "200 scale factor") + menu.AppendCheckItem(self.id_scaling_250, "250 scale factor") + menu.AppendCheckItem(self.id_scaling_300, "300 scale factor") + + self.checkmarks = { + self.id_average : lambda : self.fftsink.average, + self.id_scaling_100 : lambda : self.fftsink.scaling == 100, + self.id_scaling_150 : lambda : self.fftsink.scaling == 150, + self.id_scaling_200 : lambda : self.fftsink.scaling == 200, + self.id_scaling_250 : lambda : self.fftsink.scaling == 250, + self.id_scaling_300 : lambda : self.fftsink.scaling == 300, + } + + +def next_up(v, seq): + """ + Return the first item in seq that is > v. + """ + for s in seq: + if s > v: + return s + return v + +def next_down(v, seq): + """ + Return the last item in seq that is < v. + """ + rseq = list(seq[:]) + rseq.reverse() + + for s in rseq: + if s < v: + return s + return v + + +# ---------------------------------------------------------------- +# Deprecated interfaces +# ---------------------------------------------------------------- + +# returns (block, win). +# block requires a single input stream of float +# win is a subclass of wxWindow + +def make_ra_waterfallsink_f(fg, parent, title, fft_size, input_rate): + + block = ra_waterfallsink_f(fg, parent, title=title, fft_size=fft_size, + sample_rate=input_rate) + return (block, block.win) + +# returns (block, win). +# block requires a single input stream of gr_complex +# win is a subclass of wxWindow + +def make_ra_waterfallsink_c(fg, parent, title, fft_size, input_rate): + block = ra_waterfallsink_c(fg, parent, title=title, fft_size=fft_size, + sample_rate=input_rate) + return (block, block.win) + + +# ---------------------------------------------------------------- +# Standalone test app +# ---------------------------------------------------------------- + +class test_app_flow_graph (stdgui.gui_flow_graph): + def __init__(self, frame, panel, vbox, argv): + stdgui.gui_flow_graph.__init__ (self, frame, panel, vbox, argv) + + fft_size = 512 + + # build our flow graph + input_rate = 20.000e3 + + # Generate a complex sinusoid + src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000) + #src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000) + + # We add these throttle blocks so that this demo doesn't + # suck down all the CPU available. Normally you wouldn't use these. + thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate) + + sink1 = ra_waterfallsink_c (self, panel, title="Complex Data", fft_size=fft_size, + sample_rate=input_rate, baseband_freq=100e3) + vbox.Add (sink1.win, 1, wx.EXPAND) + self.connect (src1, thr1, sink1) + + # generate a real sinusoid + src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000) + #src2 = gr.sig_source_f (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000) + thr2 = gr.throttle(gr.sizeof_float, input_rate) + sink2 = ra_waterfallsink_f (self, panel, title="Real Data", fft_size=fft_size, + sample_rate=input_rate, baseband_freq=100e3) + vbox.Add (sink2.win, 1, wx.EXPAND) + self.connect (src2, thr2, sink2) + +def main (): + app = stdgui.stdapp (test_app_flow_graph, + "Waterfall Sink Test App") + app.MainLoop () + +if __name__ == '__main__': + main () diff --git a/gr-radio-astronomy/src/python/usrp_ra_receiver.py b/gr-radio-astronomy/src/python/usrp_ra_receiver.py index 22a30820b..cdc5b6e19 100755 --- a/gr-radio-astronomy/src/python/usrp_ra_receiver.py +++ b/gr-radio-astronomy/src/python/usrp_ra_receiver.py @@ -25,7 +25,7 @@ from gnuradio import usrp import usrp_dbid from gnuradio import eng_notation from gnuradio.eng_option import eng_option -from gnuradio.wxgui import stdgui, ra_fftsink, ra_stripchartsink, waterfallsink, form, slider +from gnuradio.wxgui import stdgui, ra_fftsink, ra_stripchartsink, ra_waterfallsink, form, slider from optparse import OptionParser import wx import sys @@ -79,13 +79,25 @@ class app_flow_graph(stdgui.gui_flow_graph): parser.add_option("-A", "--calib_coeff", type="eng_float", default=1.0, help="Calibration coefficient") parser.add_option("-B", "--calib_offset", type="eng_float", default=0.0, help="Calibration coefficient") parser.add_option("-Q", "--calib_eqn", default="x = x * 1.0", help="Calibration equation") + parser.add_option("-W", "--waterfall", action="store_true", default=False, help="Use Waterfall FFT display") + parser.add_option("-S", "--setimode", action="store_true", default=False, help="Enable SETI processing of spectral data") + parser.add_option("-T", "--setitimer", type="eng_float", default=15.0, help="Timer for computing doppler chirp for SETI analysis") + parser.add_option("-K", "--setik", type="eng_float", default=1.5, help="K value for SETI analysis") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() sys.exit(1) self.show_debug_info = True - + self.waterfall = options.waterfall + self.setimode = options.setimode + self.seticounter = 0 + self.setitimer = int(options.setitimer) + self.setik = options.setik + self.hitcounter = 0 + self.CHIRP_LOWER = 15 + self.CHIRP_UPPER = 50 + # Calibration coefficient and offset self.calib_coeff = options.calib_coeff self.calib_offset = options.calib_offset @@ -134,12 +146,19 @@ class app_flow_graph(stdgui.gui_flow_graph): # values. Used later by self.write_spectral_data() to write # spectral data to datalogging files. self.fft_outbuf = Numeric.zeros(options.fft_size, Numeric.Float64) + self.old_hits = Numeric.zeros(10, Numeric.Float64) + self.older_hits = Numeric.zeros(10, Numeric.Float64) # Set up FFT display - self.scope = ra_fftsink.ra_fft_sink_c (self, panel, - fft_size=int(self.fft_size), sample_rate=input_rate, - fft_rate=int(self.fft_rate), title="Spectral", - ofunc=self.fft_outfunc, xydfunc=self.xydfunc) + if self.waterfall == False: + self.scope = ra_fftsink.ra_fft_sink_c (self, panel, + fft_size=int(self.fft_size), sample_rate=input_rate, + fft_rate=int(self.fft_rate), title="Spectral", + ofunc=self.fft_outfunc, xydfunc=self.xydfunc) + else: + self.scope = ra_waterfallsink.ra_waterfallsink_c (self, panel, + fft_size=int(self.fft_size), sample_rate=input_rate, + fft_rate=int(self.fft_rate), title="Spectral", ofunc=self.fft_outfunc, xydfunc=self.xydfunc) # Set up ephemeris data self.locality = ephem.Observer() @@ -510,6 +529,9 @@ class app_flow_graph(stdgui.gui_flow_graph): # Continuum detector value sx = "%7.4f" % x s = s + "\nDet: " + str(sx) + sx = "%2d" % self.hitcounter + sy = "%2d" % self.CHIRP_LOWER + s = s + "\nH: " + str(sx) + " Cl: " + str(sy) self.myform['lmst_high'].set_value(s) # @@ -518,6 +540,9 @@ class app_flow_graph(stdgui.gui_flow_graph): self.write_continuum_data(x,sidtime) self.write_spectral_data(self.fft_outbuf,sidtime) + if self.setimode == True: + self.seti_analysis(self.fft_outbuf,sidtime) + def fft_outfunc(self,data,l): self.fft_outbuf=data @@ -599,6 +624,124 @@ class app_flow_graph(stdgui.gui_flow_graph): return(data) + def seti_analysis(self,fftbuf,sidtime): + l = len(fftbuf) + x = 0 + hits = [] + if self.seticounter < self.setitimer: + self.seticounter = self.seticounter + 1 + return + else: + self.seticounter = 0 + + # Run through FFT output buffer, computing standard deviation (Sigma) + avg = 0 + # First compute average + for i in range(0,l): + avg = avg + fftbuf[i] + avg = avg / l + + sigma = 0.0 + # Then compute standard deviation (Sigma) + for i in range(0,l): + d = fftbuf[i] - avg + sigma = sigma + (d*d) + + sigma = Numeric.sqrt(sigma/l) + + # + # Snarfle through the FFT output buffer again, looking for + # outlying data points + + start_f = self.observing - (self.bw/2) + current_f = start_f + f_incr = self.bw / l + l = len(fftbuf) + hit = -1 + + # -nyquist to DC + for i in range(l/2,l): + # + # If current FFT buffer has an item that exceeds the specified + # sigma + # + if ((fftbuf[i] - avg) > (self.setik * sigma)): + hits.append(current_f) + current_f = current_f + f_incr + + # DC to nyquist + for i in range(0,l/2): + # + # If current FFT buffer has an item that exceeds the specified + # sigma + # + if ((fftbuf[i] - avg) > (self.setik * sigma)): + hits.append(current_f) + current_f = current_f + f_incr + + if (len(hits) <= 0): + return + + if (len(hits) > len(self.old_hits)*2): + return + + # + # + # Calculate chirp limits from first principles + # + # + earth_diam = 12500 + earth_circ = earth_diam * 3.14159 + surface_speed = earth_circ / 24 + surface_speed = surface_speed / 3600 + + c1 = (surface_speed/2) / 299792.0 + c2 = (surface_speed*5) / 299792.0 + + self.CHIRP_LOWER = (c1 * self.observing) * self.setitimer + self.CHIRP_UPPER = (c2 * self.observing) * self.setitimer + + # + # Run through all three hit buffers, computing difference between + # frequencies found there, if they're all within the chirp limits + # declare a good hit + # + good_hit = 0 + for i in range(0,min(len(hits),len(self.old_hits))): + f_diff = abs(self.old_hits[i] - hits[i]) + f_diff2 = abs(self.older_hits[i] - self.old_hits[i]) + # If frequency difference is within range, we have a hit + if (f_diff >= self.CHIRP_LOWER and f_diff <= self.CHIRP_UPPER): + if (f_diff2 >= self.CHIRP_LOWER and f_diff <= self.CHIRP_UPPER): + good_hit = 1 + self.hitcounter = self.hitcounter + 1 + break + + if (good_hit != 0): + self.write_hits(hits,sidtime) + + # Save old hits + for i in range(0,len(self.older_hits)): + self.older_hits[i] = self.old_hits[i] + self.old_hits[i] = 0 + for i in range(0,min(len(hits),len(self.old_hits))): + self.old_hits[i] = hits[i] + + return + + def write_hits(self,hits,sidtime): + # Create localtime structure for producing filename + foo = time.localtime() + pfx = self.prefix + filenamestr = "%s/%04d%02d%02d%02d" % (pfx, foo.tm_year, + foo.tm_mon, foo.tm_mday, foo.tm_hour) + + # Open the data file, appending + hits_file = open (filenamestr+".seti","a") + hits_file.write(str(ephem.hours(sidtime))+" "+str(hits)+"\n") + hits_file.close() + return + def xydfunc(self,xyv): magn = int(Numeric.log10(self.observing)) if (magn == 6 or magn == 7 or magn == 8): -- cgit