diff options
author | n4hy | 2008-07-04 01:26:58 +0000 |
---|---|---|
committer | n4hy | 2008-07-04 01:26:58 +0000 |
commit | ae0ca251c8384b97ef1ba69a13c02227a57eaa54 (patch) | |
tree | b6c309a320c12f8798878461b83b110e9a6d2578 /gr-msdd6000/src/python_test/spectrogram.py | |
parent | 20615905cd0bf22772740d132be439bcf7ec4d8d (diff) | |
download | gnuradio-ae0ca251c8384b97ef1ba69a13c02227a57eaa54.tar.gz gnuradio-ae0ca251c8384b97ef1ba69a13c02227a57eaa54.tar.bz2 gnuradio-ae0ca251c8384b97ef1ba69a13c02227a57eaa54.zip |
cleaning up and putting much better code in. Step 1 of 2
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8778 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-msdd6000/src/python_test/spectrogram.py')
-rw-r--r-- | gr-msdd6000/src/python_test/spectrogram.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/gr-msdd6000/src/python_test/spectrogram.py b/gr-msdd6000/src/python_test/spectrogram.py new file mode 100644 index 000000000..015dd9105 --- /dev/null +++ b/gr-msdd6000/src/python_test/spectrogram.py @@ -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]; + + |