summaryrefslogtreecommitdiff
path: root/gr-msdd6000/src/python_test/spectrogram.py
blob: 015dd9105ea1013d59438ec9d0be9dc2749928a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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];