11 from numpy.fft import *;
14 myport = randint(1025,65535);
15 filename = "output.dat";
18 msdd_host = "10.45.4.46"
22 my_udp_addr = ('',randint(1025,65535));
24 UDPSock = socket(AF_INET,SOCK_DGRAM);
25 UDPSock.bind(my_udp_addr);
29 print "fc = %d"%(f_mhz);
32 gain = 20; # attenuation
33 window = 3; #0=rect, 1=hanning, 2=hamming, 3=blackman
37 #samples = 16*1024*1024;
38 #samples = samples*4; #bytes of data we are requesting
43 decim = decim+16; # +16 to use 16bit floats instead of 32 bit floats
44 mode = 0; #0=IQ, 1=MAG, 2=MAGDB
49 request_len = 6*size_int; # 6 int items not including the 8 bytes for opcode and length fields
50 print "request len = %d"%(request_len);
52 raw_data = struct.pack("<IIIIIIII", 0x01, request_len, f_mhz, f_hz, gain, samples, decim, sets);
56 UDPSock.sendto(data, (msdd_host, msdd_port));
77 IQ_bytes = 4 * numtocap;
88 while(num_rx < numbytes):
89 data = UDPSock.recv(1024);
91 num_rx = num_rx + len(data);
97 halt_data = struct.pack(">II", 0x04, 0x00);
98 UDPSock.sendto(halt_data, (msdd_host, msdd_port));
100 # perform timing analysis
101 print "recieved %d bytes in %f sec"%(numbytes, end-start);
102 bytes_per_sec = numbytes / (end-start);
103 samples_per_sec = bytes_per_sec / 4;
104 MSPS = samples_per_sec / 1000000.0;
106 print "Got %f MSPS"%(MSPS);
107 print "Expected %f MSPS"%(102.4/math.pow(2,(decim-16)));
115 print "Repacking data..."
116 f = open("out.dat","w");
118 for p in range(0, len(li)/4):
119 [i,q] = struct.unpack_from("<hh", li, p*4);
121 mag_arr.append((val*conj(val)).real);
123 binchunk = struct.pack("<ff",float(val.real), float(val.imag) );
128 dlen = len(val_arr)-1;
130 for i in range(1, dlen-1024, 1024*1024):
133 for ind in range(i, i+1024):
134 t_in.append(val_arr[ind]);
136 tmp = 20*log10(fftshift(fft(t_in)));
137 #tmp = (fftshift(fft(t_in)));
139 if(len(fft_data) == 0):
140 for ind in range(0,1024):
141 fft_data.append( tmp[ind] );
143 for ind in range(0,1024):
144 fft_data[ind] = fft_data[ind] + tmp[ind];
154 plot(10*log10(fft_data));