commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8778 - in gnuradio/trunk/gr-msdd6000/src: . python_te


From: n4hy
Subject: [Commit-gnuradio] r8778 - in gnuradio/trunk/gr-msdd6000/src: . python_test
Date: Thu, 3 Jul 2008 19:26:58 -0600 (MDT)

Author: n4hy
Date: 2008-07-03 19:26:58 -0600 (Thu, 03 Jul 2008)
New Revision: 8778

Added:
   gnuradio/trunk/gr-msdd6000/src/python_test/capture_tcp_one_set.py
   gnuradio/trunk/gr-msdd6000/src/python_test/flood_udp.py
   gnuradio/trunk/gr-msdd6000/src/python_test/halt.py
   gnuradio/trunk/gr-msdd6000/src/python_test/newtest.py
   gnuradio/trunk/gr-msdd6000/src/python_test/spectrogram.py
   gnuradio/trunk/gr-msdd6000/src/python_test/test_tcp_fft.py
   gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_cap.py
   gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test.py
   gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot.py
   gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot_loop.py
   gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_test.py
Removed:
   gnuradio/trunk/gr-msdd6000/src/lib/
   gnuradio/trunk/gr-msdd6000/src/python/
Modified:
   gnuradio/trunk/gr-msdd6000/src/Makefile.am
   gnuradio/trunk/gr-msdd6000/src/python_test/test_udp.py
Log:
cleaning up and putting much better code in. Step 1 of 2

Modified: gnuradio/trunk/gr-msdd6000/src/Makefile.am
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/Makefile.am  2008-07-04 00:14:42 UTC (rev 
8777)
+++ gnuradio/trunk/gr-msdd6000/src/Makefile.am  2008-07-04 01:26:58 UTC (rev 
8778)
@@ -18,5 +18,85 @@
 # the Free Software Foundation, Inc., 51 Franklin Street,
 # Boston, MA 02110-1301, USA.
 # 
+CCFLAGS = -g
+include $(top_srcdir)/Makefile.common
 
-SUBDIRS = lib python
+# Install this stuff so that it ends up as the gnuradio.howto module
+# This usually ends up at:
+#   ${prefix}/lib/python${python_version}/site-packages/gnuradio
+
+ourpythondir = $(grpythondir)
+ourlibdir    = $(grpyexecdir)
+
+INCLUDES = $(STD_DEFINES_AND_INCLUDES) $(PYTHON_CPPFLAGS)
+
+SWIGPYTHONARGS = $(SWIGPYTHONFLAGS) $(SWIGGRFLAGS)
+
+ALL_IFILES =                           \
+       $(LOCAL_IFILES)                 \
+       $(NON_LOCAL_IFILES)             
+
+NON_LOCAL_IFILES =                     \
+       $(GNURADIO_CORE_INCLUDEDIR)/swig/gnuradio.i
+
+
+LOCAL_IFILES =                                 \
+       $(top_srcdir)/src/msdd/msdd.i                           
+
+# These files are built by SWIG.  The first is the C++ glue.
+# The second is the python wrapper that loads the _howto shared library
+# and knows how to call our extensions.
+
+BUILT_SOURCES =                        \
+       msdd.cc                 \
+       msdd.py                         
+
+# This gets howto.py installed in the right place
+ourpython_PYTHON =                     \
+       msdd.py
+
+ourlib_LTLIBRARIES = _msdd.la
+
+# These are the source files that go into the shared library
+_msdd_la_SOURCES =                     \
+       msdd.cc                 \
+       msdd_source_base.cc     \
+       msdd_source_c.cc        \
+       msdd_source_simple.cc   \
+       msdd_source_s.cc        \
+       msdd6000.cc
+
+# magic flag
+_msdd_la_LDFLAGS = $(NO_UNDEFINED) -module -avoid-version 
+#-lfftw3 -lfftw3f -lfann 
+
+# link the library against some comon swig runtime code and the 
+# c++ standard library
+_msdd_la_LIBADD =                      \
+       $(PYTHON_LDFLAGS)               \
+       -lstdc++
+# -L/usr/lib/libfftw3f.so.3.1.2
+
+msdd.cc msdd.py: $(LOCAL_IFILES) $(ALL_IFILES) 
+       $(SWIG) $(SWIGPYTHONARGS) -module msdd -o msdd.cc $(LOCAL_IFILES)
+
+# These headers get installed in ${prefix}/include/gnuradio
+grinclude_HEADERS =                    \
+       msdd_source_base.h              \
+       msdd_source_c.h                 \
+       msdd_source_simple.h                    \
+       msdd_source_s.h                 
+
+
+
+# These swig headers get installed in ${prefix}/include/gnuradio/swig
+swiginclude_HEADERS =                  \
+       $(LOCAL_IFILES)
+
+
+MOSTLYCLEANFILES = $(BUILT_SOURCES) *.pyc
+
+# Don't distribute output of swig
+dist-hook:
+       @for file in $(BUILT_SOURCES); do echo $(RM) $(distdir)/$$file; done
+       @for file in $(BUILT_SOURCES); do $(RM) $(distdir)/$$file; done

Added: gnuradio/trunk/gr-msdd6000/src/python_test/capture_tcp_one_set.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/capture_tcp_one_set.py           
                (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/capture_tcp_one_set.py   
2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,156 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+port = 10000
+host = "10.45.4.46"
+#host = "10.45.4.41"
+myaddr = ('',myport);
+
+buf = 100000;
+
+TCPSock = socket(AF_INET,SOCK_STREAM);
+TCPSock.bind(myaddr);
+TCPSock.connect((host,port));
+
+#f_mhz = 2647; # roof ofdm
+if(len(sys.argv)!= 3):
+       print "usage: %s  fc_ghz   decim_pow2_exponent"%(sys.argv[0]);
+       sys.exit(-1);
+
+f_mhz = float(sys.argv[1])*1000;
+decim = int(sys.argv[2]);
+
+#f_mhz = 3500;
+#f_mhz = 2600;
+f_hz = 0;      # offset        
+gain = 0;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+samples = 65536;
+#samples = 16777216;
+samples = samples*4;   #bytes of data we are requesting
+samples=samples*2;
+#decim = 2;    #0-8   (3 => 2^3 = 8)  
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+sets = 1;
+
+raw_data = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, gain, samples, 
decim, sets);
+
+data = raw_data;
+
+TCPSock.send(data);
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+while(TCPSock):
+       if(state==0):
+               data = TCPSock.recv(4);
+               [opcode] = struct.unpack("<I", data);
+               print "Opcode = %d"%(opcode);
+               if(opcode==1):
+                       state = 1;
+
+       elif(state==1):
+               data = TCPSock.recv(7*4);
+               args = struct.unpack("<IIIIIII", data);
+               print ["reply_len", "freq_mhz", "offset_hz", "gain", 
"sample_bytes", "decim", "sets_remain"];
+               print args;
+               IQ_bytes = args[0] - 7*4;
+               state =2;
+
+       elif(state==2):
+               data = TCPSock.recv(4);
+               [i,q] = struct.unpack("<hh", data);
+               tmp = complex(i,q);
+
+               re.append(i);
+               vals.append(tmp);
+               mags.append(abs(tmp));
+
+
+               sample_count = sample_count + 1;
+#              print "sample count %d"%(sample_count)  
+
+               IQ_bytes = IQ_bytes - 4;
+               if(IQ_bytes < 4):
+                       print "got all data (total %d)"%(sample_count);
+                       print "remaining: %d"%(IQ_bytes);
+                       break;
+
+
+TCPSock.close();
+
+print "done"
+nmags = []
+for i in mags:
+       if i == 0:
+               i=1;
+       nmags.append(i);
+
+
+subplot(2,1,1);
+plot(nmags);
+#plot(10*log10(nmags));
+
+dlen = len(vals);
+fftlen = (dlen-1024)/1024;
+
+fft_data = []
+for i in range(1, dlen-1025, 1024):
+
+       t_in = [];
+       for ind in range(i, i+1024):
+               t_in.append(vals[ind]);
+
+       #tmp = 20*log10(fftshift(fft(t_in)));
+       tmp = (fftshift(fft(t_in)));
+
+       if(len(fft_data) == 0):
+               for ind in range(0,1024):
+                       fft_data.append( tmp[ind] );
+       else:
+               for ind in range(0,1024):
+                       fft_data[ind] = fft_data[ind] + tmp[ind];
+
+#fft_data = 20*log10(fftshift(fft(vals)));
+
+
+subplot(2,1,2);
+plot(fft_data);
+show();
+
+f = open(filename, "w");
+for sample in vals:
+       binchunk = struct.pack("<ff",float(sample.real), float(sample.imag) );
+       f.write(binchunk);
+f.close();
+
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/flood_udp.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/flood_udp.py                     
        (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/flood_udp.py     2008-07-04 
01:26:58 UTC (rev 8778)
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+
+msdd_port = 10001
+msdd_host = "10.45.4.43"
+
+my_udp_addr = ("10.45.1.229",10001);
+
+buf = 1024;
+
+#myport = random.randint(1025,65535);
+#my_tcp_addr = ("10.45.1.229",myport);
+#TCPSock = socket(AF_INET,SOCK_STREAM);
+#TCPSock.bind(my_tcp_addr);
+#TCPSock.connect((msdd_host,msdd_port));
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+SETS_STREAM = 0xffffffff;
+
+f_mhz = 2400;
+f_hz = 1;
+gain = 3;
+samples = 512;
+decim = 4;
+#sets = 16;
+sets = SETS_STREAM;
+window =  3;
+mode = 1;
+
+
+
+for first_byte in range(0,0xff):
+       for second_byte in range(0,0xff):
+               for third_byte in range(0,0xff):
+                       data = struct.pack("!III", first_byte, 
second_byte,third_byte);
+                       UDPSock.sendto(data, (msdd_host,msdd_port))
+
+       
+# construct the 3 different request type packets
+#fft_data = struct.pack("<IIIIIIIIII", 0x02, 0x20, f_mhz, f_hz, gain,window, 
samples, decim, mode,sets);
+#raw_data = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, gain,samples, 
decim,sets);
+#stat_data = struct.pack("!II", 0x0000, 0x0000)
+
+# send appropriate udp request packet
+
+
+
+
+
+
+
+
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/halt.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/halt.py                          
(rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/halt.py  2008-07-04 01:26:58 UTC 
(rev 8778)
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.43"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+halt_data = struct.pack("<II", 0x04, 0x00);
+halt_data = struct.pack("<II", 0x04, 0x00);
+
+data = halt_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+UDPSock.close();
+
+
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/newtest.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/newtest.py                       
        (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/newtest.py       2008-07-04 
01:26:58 UTC (rev 8778)
@@ -0,0 +1,140 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.43"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+#f_mhz = 3500; 
+#f_mhz = 3500; 
+f_mhz = 100;   
+f_hz = 0;      
+gain = 0;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+samples = 12000;
+samples = samples*4;   #bytes of data we are requesting
+
+decim = 2;     #0-8   (3 => 2^3 = 8)  
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+#raw_data = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, gain, samples, 
decim, sets);
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+while(True):
+       print state;
+       if(state==0):
+               data = UDPSock.recv(4);
+               [opcode] = struct.unpack("<I", data);
+               print "Opcode = %d"%(opcode);
+               if(opcode==1):
+
+                       # if UDP mode and sets_stream requested,
+                       # we do not get a header reply back, only data
+                       if(sets == 0):
+                               state = 1;
+                       else:
+                               state = 2;
+
+       elif(state==1):
+               data = UDPSock.recv(7*4);
+               args = struct.unpack("<IIIIIII", data);
+               print ["reply_len", "freq_mhz", "offset_hz", "gain", 
"sample_bytes", "decim", "sets_remain"];
+               print args;
+               IQ_bytes = args[0] - 7*4;
+               state =2;
+
+       elif(state==2):
+               data = UDPSock.recv(4);
+               [i,q] = struct.unpack("<hh", data);
+               tmp = complex(i,q);
+
+               re.append(i);
+               vals.append(tmp);
+               mags.append(abs(tmp));
+
+
+               sample_count = sample_count + 1;
+#              print "sample count %d"%(sample_count)  
+
+               IQ_bytes = IQ_bytes - 4;
+               if(IQ_bytes < 4):
+                       print "got all data (total %d)"%(sample_count);
+                       print "remaining: %d"%(IQ_bytes);
+                       break;
+
+
+UDPSock.close();
+
+print "done"
+nmags = []
+for i in mags:
+       if i == 0:
+               i=1;
+       nmags.append(i);
+
+
+subplot(2,1,1);
+plot(20*log10(nmags));
+
+fft_data = 20*log10(fftshift(fft(vals)));
+
+subplot(2,1,2);
+plot(fft_data);
+show();
+
+f = open(filename, "w");
+for sample in vals:
+       binchunk = struct.pack("<ff",float(sample.real), float(sample.imag) );
+       f.write(binchunk);
+f.close();
+
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/spectrogram.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/spectrogram.py                   
        (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/spectrogram.py   2008-07-04 
01:26:58 UTC (rev 8778)
@@ -0,0 +1,87 @@
+#!/usr/bin/python
+
+fft_bins = 1024;
+stride = 256;
+
+#filename = "output.dat";
+#decim = 4;
+#Fs = (102.4/decim) * 1e6;
+
+
+from gnuradio import gr;
+from Numeric import *;
+import FFT;
+import numpy.fft;
+from numpy import *;
+from pylab import *;
+import sys;
+
+if len(sys.argv) <2: 
+       print "usage:  %s filename <sample_rate_in_MSPS> 
<stride_samples>"%(sys.argv[0]);
+       sys.exit(-1);
+
+filename = sys.argv[1];
+fs = 0;
+if(len(sys.argv)>2):
+       fs = float(sys.argv[2])*1000000;
+print "opening %s.\n"%(filename);
+
+if(len(sys.argv)>=4):
+       stride = int(sys.argv[3]);
+       print "using stride = %d"%(stride);
+
+tb = gr.top_block();
+src = gr.file_source(gr.sizeof_gr_complex, filename, False)
+sink = gr.vector_sink_c();
+tb.connect(src,sink);
+tb.run();
+
+data = sink.data();
+dataa = array(data);
+datalen = len( data );
+
+time_bins = (datalen - fft_bins) / stride;
+
+print "output vector :: fft_bins = %d, time_bins = %d\n"%(fft_bins,time_bins);
+
+start_idx = 0;
+
+b = numpy.zeros((time_bins, fft_bins), complex);
+l = [];
+
+window = numpy.blackman(fft_bins);
+
+for i in range(0,time_bins):
+       
+       time_chunk = take( dataa, range(start_idx,start_idx + fft_bins), 0);
+       time_chunk = time_chunk * window;
+       fft_chunk = numpy.fft.fftshift(numpy.fft.fft(time_chunk));
+       psd = 10*log10(fft_chunk * conj(fft_chunk)+0.001);
+
+       b[i] = psd.real;
+       l.append( psd.real.tolist() );
+
+       start_idx = start_idx + stride;
+
+#c = array(b, 10);
+
+print b[0];
+c = array(b);
+#l = c.tolist();
+print size(l);
+
+x = range(0,time_bins);
+print size(x);
+y = range(0,fft_bins);
+print size(y);
+
+print size(l);
+
+contourf(l);
+#contourf([x,y], l);
+colorbar();
+show();
+
+#print c[1,1];
+
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/test_tcp_fft.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/test_tcp_fft.py                  
        (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/test_tcp_fft.py  2008-07-04 
01:26:58 UTC (rev 8778)
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+
+myport = random.randint(1025,65535);
+
+port = 10000
+host = "10.45.4.43"
+myaddr = ("10.45.1.229",myport);
+
+buf = 100000;
+
+TCPSock = socket(AF_INET,SOCK_STREAM);
+#TCPSock = socket(AF_INET,SOCK_DGRAM);
+TCPSock.bind(myaddr);
+TCPSock.connect((host,port));
+
+f_mhz = 2400;  
+f_hz = 0;      
+gain = 2;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+#samples = 0xffffffff;         #8-15   fft:(returns 2^number[8-15]) 
raw:(returns number)
+samples = 2;   #8-15   fft:(returns 2^number[8-15]) raw:(returns number)
+decim = 2;     #0-8  
+#decim = decim+16;     # +16 to use 16bit instead of 32 bit 
+mode = 1;      #0=IQ, 1=MAG, 2=MAGDB
+sets = 0xffffffff;     
+#sets = 1;
+
+fft_data = struct.pack("<IIIIIIIIII", 0x02, 0x20, f_mhz, f_hz, gain,window, 
samples, decim, mode,sets);
+raw_data = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, gain,samples, 
decim,sets);
+stat_data = struct.pack("!II", 0x0000, 0x0000)
+
+data = raw_data;
+
+#TCPSock.sendto(data, (host,port))
+TCPSock.send(data);
+
+print "sent"
+
+
+
+count = 0;
+while(1):
+       data,addr = TCPSock.recvfrom(buf);
+       
+       print "got response"
+       
+       print "Data length: %d bytes."%(len(data));
+       if(len(data)==12):
+               a,b,c = struct.unpack("!III",data);
+               print "%x,%x,%x"%(a,b,c);
+
+       datavector = [];
+
+       for d in data:
+               a = struct.unpack("<b",d);
+               datavector.append(a);
+
+       print datavector;
+               
+       count = count + 1;
+       
+       if(count > 1):
+               sets = 3;
+               raw_data_2 = struct.pack("<IIIIIIII", 0x01, 0x18, f_mhz, f_hz, 
gain,samples, decim,sets);
+               TCPSock.send(raw_data_2);
+               
+               
+               
+TCPSock.close();
+
+
+

Modified: gnuradio/trunk/gr-msdd6000/src/python_test/test_udp.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/test_udp.py      2008-07-04 
00:14:42 UTC (rev 8777)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/test_udp.py      2008-07-04 
01:26:58 UTC (rev 8778)
@@ -28,7 +28,9 @@
 f_hz = 1;
 gain = 3;
 samples = 512;
-decim = 4;
+
+decim = 2;
+
 #sets = 16;
 sets = SETS_STREAM;
 window =  3;
@@ -53,6 +55,5 @@
 data,addr = UDPSock.recvfrom(buf);
 
 print "got response"
-print data,addr
 
-
+print data;

Added: gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_cap.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_cap.py                
                (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_cap.py        
2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.43"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+#f_mhz = 3500; 
+#f_mhz = 3500; 
+f_mhz = 1000;  
+f_hz = 0;      
+gain = 0;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+#samples = 65535;
+samples = 16384;
+#samples = samples*4;  #bytes of data we are requesting
+
+decim = 4;     #0-8   (3 => 2^3 = 8)  
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+
+numtocap = 1000;
+IQ_bytes = 4 * numtocap;
+
+numbytes = 100 * 65536;
+
+num_rx = 0;
+start =  time.time();
+
+d = [];
+while(num_rx < numbytes):
+       data = UDPSock.recv(65536);
+       num_rx = num_rx + len(data);
+       d.append(data);
+
+mags = [];
+for i in range(0, len(d)/4):
+       v = struct.unpack_from("<f",d, i*4);
+       mags.append(abs(v));
+plot(mags);
+show();
+
+end = time.time();
+print "recieved %d bytes in %f sec"%(numbytes, end-start);
+
+bytes_per_sec = numbytes / (end-start);
+samples_per_sec = bytes_per_sec / 4;
+MSPS = samples_per_sec / 1000000.0;
+
+print "Got %f MSPS"%(MSPS);
+print "Expected %f MSPS"%(102.4/math.pow(2,(1+decim-16)));
+       
+
+halt_data = struct.pack("<II", 0x04, 0x00);
+UDPSock.sendto(halt_data, (msdd_host, msdd_port));
+
+
+UDPSock.close();
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test.py          
                (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test.py  
2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,106 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.46"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+#f_mhz = 3500; 
+#f_mhz = 3500; 
+f_mhz = 1000;  
+f_hz = 0;      
+gain = 0;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+#samples = 65535;
+samples = 16384;
+#samples = samples*4;  #bytes of data we are requesting
+
+decim = 2;     #0-8   (3 => 2^3 = 8)   # ok
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+
+numtocap = 1000;
+IQ_bytes = numtocap * numtocap;
+
+numbytes = 1000 * 65536;
+
+num_rx = 0;
+start = -1;
+while(num_rx < numbytes):
+       data = UDPSock.recv(65536);
+
+       if(start==-1):
+               start =  time.time();
+
+       num_rx = num_rx + len(data);
+#      print num_rx;
+
+
+end = time.time();
+print "recieved %d bytes in %f sec"%(numbytes, end-start);
+
+bytes_per_sec = numbytes / (end-start);
+samples_per_sec = bytes_per_sec / 4;
+MSPS = samples_per_sec / 1000000.0;
+
+print "Got %f MSPS"%(MSPS);
+print "Expected %f MSPS"%(102.4/math.pow(2,(decim-16)));
+       
+
+halt_data = struct.pack("<II", 0x04, 0x00);
+UDPSock.sendto(halt_data, (msdd_host, msdd_port));
+
+
+UDPSock.close();
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot.py     
                        (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot.py     
2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,161 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+from random import *;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.46"
+
+buf = 100000;
+
+my_udp_addr = ('',randint(1025,65535));
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+f_mhz = 2500;  
+
+print "fc = %d"%(f_mhz);
+
+f_hz = 0;      
+gain = 20;     # attenuation
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+samples = 65535*4*2;
+#samples = 16384;
+#samples = 16*1024*1024;
+#samples = samples*4;  #bytes of data we are requesting
+
+# decim 0-8 ( 3 - 8 )
+#decim = 5;    # rate ok
+decim = 8;
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+
+numtocap = 1000;
+IQ_bytes = 4 * numtocap;
+
+numbytes = 65536*100;
+#numbytes = 65536*2;
+#numbytes = 1024;
+
+num_rx = 0;
+start =  time.time();
+l = [];
+arr = [];
+
+while(num_rx < numbytes):
+       data = UDPSock.recv(1024);
+       l.append(data);
+       num_rx = num_rx + len(data);
+
+
+end = time.time();
+
+# send stop command
+halt_data = struct.pack(">II", 0x04, 0x00);
+UDPSock.sendto(halt_data, (msdd_host, msdd_port));
+
+# perform timing analysis
+print "recieved %d bytes in %f sec"%(numbytes, end-start);
+bytes_per_sec = numbytes / (end-start);
+samples_per_sec = bytes_per_sec / 4;
+MSPS = samples_per_sec / 1000000.0;
+
+print "Got %f MSPS"%(MSPS);
+print "Expected %f MSPS"%(102.4/math.pow(2,(decim-16)));
+
+
+# plot data
+val_arr = [];
+mag_arr = [];
+mag_arr2 = [];
+
+print "Repacking data..."
+f = open("out.dat","w");
+for li in l:
+       for p in range(0, len(li)/4):
+               [i,q] = struct.unpack_from("<hh", li, p*4);
+               val = complex(i,q);
+               mag_arr.append((val*conj(val)).real);
+               val_arr.append(val);
+               binchunk = struct.pack("<ff",float(val.real), float(val.imag) );
+               f.write(binchunk);
+f.close();
+               
+
+dlen = len(val_arr)-1;
+fft_data = [];
+for i in range(1, dlen-1024, 1024*1024):
+
+        t_in = [];
+        for ind in range(i, i+1024):
+                t_in.append(val_arr[ind]);
+
+        tmp = 20*log10(fftshift(fft(t_in)));
+        #tmp = (fftshift(fft(t_in)));
+
+        if(len(fft_data) == 0):
+                for ind in range(0,1024):
+                        fft_data.append( tmp[ind] );
+        else:
+                for ind in range(0,1024):
+                        fft_data[ind] = fft_data[ind] + tmp[ind];
+
+
+
+
+print "Plotting..."
+subplot(2,1,1);
+plot(mag_arr);
+title("T power");
+subplot(2,1,2);
+plot(10*log10(fft_data));
+title("PSD");
+show();
+
+
+
+UDPSock.close();
+

Added: 
gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot_loop.py
===================================================================
--- 
gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot_loop.py    
                            (rev 0)
+++ 
gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_rate_test_plot_loop.py    
    2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,150 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+#msdd_host = "10.45.4.43"
+msdd_host = "10.45.4.45"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+#f_mhz = 3500; 
+f_mhz = 1500;  
+#f_mhz = 1000; 
+f_hz = 0;      
+gain = 80;     
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+#samples = 65535;
+samples = 16384;
+#samples = samples*4;  #bytes of data we are requesting
+
+# decim 0-8 ( 3 - 8 )
+#decim = 5;    # rate ok
+decim = 4;
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+start =  time.time();
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+
+numtocap = 1000;
+IQ_bytes = 4 * numtocap;
+
+#numbytes = 65536*100;
+numbytes = 65536;
+
+
+
+while(True):
+
+       data = [];
+       l = [];
+       num_rx = 0;
+       while(num_rx < numbytes):
+               data = UDPSock.recv(65536);
+               num_rx = num_rx + len(data);
+               l.append(data);
+
+       end = time.time();
+       
+       # send stop command
+       #halt_data = struct.pack("<II", 0x04, 0x00);
+       #UDPSock.sendto(halt_data, (msdd_host, msdd_port));
+       
+       # perform timing analysis
+       print "recieved %d bytes in %f sec"%(numbytes, end-start);
+       bytes_per_sec = numbytes / (end-start);
+       samples_per_sec = bytes_per_sec / 4;
+       MSPS = samples_per_sec / 1000000.0;
+       
+       print "Got %f MSPS"%(MSPS);
+       print "Expected %f MSPS"%(102.4/math.pow(2,(decim-16)));
+       
+       
+       # plot data
+       val_arr = [];
+       mag_arr = [];
+       
+       print "Repacking data..."
+       for li in l:
+               for p in range(0, len(li)/4):
+                       [i,q] = struct.unpack_from("<hh", li, p);
+                       val = complex(i,q);
+                       mag_arr.append(abs(val));
+                       val_arr.append(val);
+       
+       
+       print "Calculating Time Domain Power..."
+       tpwr = [];
+       for i in val_arr:
+               tpwr.append( (i*conj(i)).real );
+       
+       print "Calculating PSD..."
+       freqz = fft(val_arr);
+       
+       #freqz = [];
+       #
+       #for i in range(0, floor(len(val_arr)/2048)):
+       #       tmp = val_arr(range(i,i+2048));
+       #       if len(freqz) == 0:
+       #               freqz = tmp;
+       #       
+       
+       psd = (freqz * conj(freqz)).real;
+       
+       print "Plotting..."
+       subplot(2,1,1);
+       plot(tpwr);
+       subplot(2,1,2);
+       plot(10*log10(psd));
+       show();
+       
+UDPSock.close();
+

Added: gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_test.py
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_test.py               
                (rev 0)
+++ gnuradio/trunk/gr-msdd6000/src/python_test/udp_stream_test.py       
2008-07-04 01:26:58 UTC (rev 8778)
@@ -0,0 +1,127 @@
+#!/usr/bin/python
+
+from socket import *
+import string
+import time
+import struct;
+import random;
+import array;
+import cmath;
+from numpy import *;
+from numpy.fft import *;
+from pylab import *;
+
+myport = random.randint(1025,65535);
+filename = "output.dat";
+
+msdd_port = 10001
+msdd_host = "10.45.4.46"
+
+buf = 100000;
+
+my_udp_addr = ('',10001);
+my_udp_addr = ('10.45.1.229 ',10001);
+
+UDPSock = socket(AF_INET,SOCK_DGRAM);
+UDPSock.bind(my_udp_addr);
+
+#f_mhz = 3500; 
+#f_mhz = 3500; 
+f_mhz = 2500;  
+f_hz = 0;      
+gain = 0;      
+window = 3;    #0=rect, 1=hanning, 2=hamming, 3=blackman
+
+samples = 65535;
+samples = samples*4;   #bytes of data we are requesting
+
+decim = 2;     #0-8   (3 => 2^3 = 8)  
+decim = decim+16;      # +16 to use 16bit floats instead of 32 bit floats
+mode = 0;      #0=IQ, 1=MAG, 2=MAGDB
+#sets = 0;
+sets = 0xffffffff;
+
+size_int = 4;
+request_len = 6*size_int;      # 6 int items not including the 8 bytes for 
opcode and length fields
+print "request len = %d"%(request_len);
+
+raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, 
samples, decim, sets);
+
+data = raw_data;
+
+UDPSock.sendto(data, (msdd_host, msdd_port));
+
+print "sent"
+
+
+
+count = 0;
+
+total_data = [];
+
+state = 0;
+
+vals = [];
+mags = [];
+re = [];
+
+sample_count = 0;
+IQ_bytes=0;
+
+
+numtocap = 1000;
+IQ_bytes = 4 * numtocap;
+
+while(True):
+       data = UDPSock.recv(4);
+       [i,q] = struct.unpack("<hh", data);
+       tmp = complex(i,q);
+
+       re.append(i);
+       vals.append(tmp);
+       mags.append(abs(tmp));
+
+
+       sample_count = sample_count + 1;
+#      print "sample count %d"%(sample_count)  
+
+       IQ_bytes = IQ_bytes - 4;
+       if(IQ_bytes % 200 == 0):
+               print IQ_bytes;
+       if(IQ_bytes < 4):
+               print "got all data (total %d)"%(sample_count);
+               print "remaining: %d"%(IQ_bytes);
+               break;
+
+
+halt_data = struct.pack("<II", 0x04, 0x00);
+UDPSock.sendto(halt_data, (msdd_host, msdd_port));
+
+
+
+UDPSock.close();
+
+print "done"
+nmags = []
+for i in mags:
+       if i == 0:
+               i=1;
+       nmags.append(i);
+
+
+subplot(2,1,1);
+plot(20*log10(nmags));
+
+fft_data = 20*log10(fftshift(fft(vals)));
+
+subplot(2,1,2);
+plot(fft_data);
+show();
+
+f = open(filename, "w");
+for sample in vals:
+       binchunk = struct.pack("<ff",float(sample.real), float(sample.imag) );
+       f.write(binchunk);
+f.close();
+
+





reply via email to

[Prev in Thread] Current Thread [Next in Thread]