Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Jie_Wang/spectrum-monitor
1 result
Show changes
Commits on Source (2)
...@@ -23,7 +23,7 @@ START_FREQ = 100e6 ...@@ -23,7 +23,7 @@ START_FREQ = 100e6
END_FREQ = 6000e6 END_FREQ = 6000e6
MAX_INST_BW = 30.72e6 MAX_INST_BW = 30.72e6
ANALOG_BW_CUTOFF_FACTOR = 0.9 #0.82 ANALOG_BW_CUTOFF_FACTOR = 0.9
# Effective bandwidth we are monitoring # Effective bandwidth we are monitoring
ANALOG_BW = MAX_INST_BW * ANALOG_BW_CUTOFF_FACTOR # 27e6 ANALOG_BW = MAX_INST_BW * ANALOG_BW_CUTOFF_FACTOR # 27e6
...@@ -59,7 +59,7 @@ COLLECT_SAMPLE = 0 ...@@ -59,7 +59,7 @@ COLLECT_SAMPLE = 0
OFFSET_TEST = 0 OFFSET_TEST = 0
# tune request takes lo_offset # tune request takes lo_offset
OFFSET = 0 #0.43 * MAX_INST_BW OFFSET = 0
#---------------------------------------------------------- #----------------------------------------------------------
#---------------------------------------------------------- #----------------------------------------------------------
...@@ -67,7 +67,7 @@ OFFSET = 0 #0.43 * MAX_INST_BW ...@@ -67,7 +67,7 @@ OFFSET = 0 #0.43 * MAX_INST_BW
#---------------------------------------------------------- #----------------------------------------------------------
# total data points collected # total data points collected
N_SAMPLES = int(1e4) #int(2e4) N_SAMPLES = int(10240) #int(2e4)
#---------------------------------------------------------- #----------------------------------------------------------
......
...@@ -97,7 +97,7 @@ class Device(): ...@@ -97,7 +97,7 @@ class Device():
# set to a default value to initialize the radio # set to a default value to initialize the radio
for chan in self.chans: for chan in self.chans:
self.usrp.set_rx_rate(self.rate, chan) self.usrp.set_rx_rate(self.rate, chan) #C.MAX_INST_BW
self.usrp.set_rx_freq(uhd.libpyuhd.types.tune_request(2400e6,C.OFFSET), chan) self.usrp.set_rx_freq(uhd.libpyuhd.types.tune_request(2400e6,C.OFFSET), chan)
self.usrp.set_rx_gain(self.gain, chan) self.usrp.set_rx_gain(self.gain, chan)
......
...@@ -346,8 +346,6 @@ class IsoReceiver(receiver.Receiver): ...@@ -346,8 +346,6 @@ class IsoReceiver(receiver.Receiver):
f.close() f.close()
# shuffle data # shuffle data
seed = random.randint(5, 50)
np.random.seed(seed) #for reproducibility
shuffled_indices = np.arange(len(Center_freqs)) shuffled_indices = np.arange(len(Center_freqs))
np.random.shuffle(shuffled_indices) np.random.shuffle(shuffled_indices)
Freqs_shuffle = Center_freqs[shuffled_indices] Freqs_shuffle = Center_freqs[shuffled_indices]
...@@ -364,7 +362,7 @@ class IsoReceiver(receiver.Receiver): ...@@ -364,7 +362,7 @@ class IsoReceiver(receiver.Receiver):
save_samp0 = np.reshape(real_img0, -1, order='F') save_samp0 = np.reshape(real_img0, -1, order='F')
save_samp0 = save_samp0.reshape(-1,1) save_samp0 = save_samp0.reshape(-1,1)
a = array(save_samp0,'float32') a = np.array(save_samp0,'float32')
output_file = open('sample0.txt', 'wb') output_file = open('sample0.txt', 'wb')
a.tofile(output_file) a.tofile(output_file)
output_file.close() output_file.close()
...@@ -373,7 +371,7 @@ class IsoReceiver(receiver.Receiver): ...@@ -373,7 +371,7 @@ class IsoReceiver(receiver.Receiver):
save_samp1 = np.reshape(real_img1, -1, order='F') save_samp1 = np.reshape(real_img1, -1, order='F')
save_samp1 = save_samp1.reshape(-1,1) save_samp1 = save_samp1.reshape(-1,1)
a = array(save_samp1,'float32') a = np.array(save_samp1,'float32')
output_file = open('sample1.txt', 'wb') output_file = open('sample1.txt', 'wb')
a.tofile(output_file) a.tofile(output_file)
output_file.close() output_file.close()
...@@ -410,9 +408,9 @@ class IsoReceiver(receiver.Receiver): ...@@ -410,9 +408,9 @@ class IsoReceiver(receiver.Receiver):
freqs_out[m,:] = freqs/1e6 freqs_out[m,:] = freqs/1e6
# extend devs, times to match the number of lines found per iteration. # extend devs, times to match the number of lines found per iteration.
trep = np.tile(int(time.time()), C.N_BINS_OUT_PER_STEP ) # C.N_SAMPLES trep = np.tile(int(time.time()), C.N) # C.N_SAMPLES
devrep = np.tile(rf_port, C.N_BINS_OUT_PER_STEP) devrep = np.tile(rf_port, C.N)
cfrep = np.tile(center_freq/1e6, C.N_BINS_OUT_PER_STEP) cfrep = np.tile(Center_freqs[m]/1e6, C.N)
times = np.append(times, trep) times = np.append(times, trep)
devs = np.append(devs, devrep) devs = np.append(devs, devrep)
......
...@@ -50,7 +50,7 @@ class source_separation(object): ...@@ -50,7 +50,7 @@ class source_separation(object):
FFT_R0_ori = np.fft.fftshift(FFT_R0_ori) FFT_R0_ori = np.fft.fftshift(FFT_R0_ori)
FFT_R1_ori = np.fft.fftshift(FFT_R1_ori) FFT_R1_ori = np.fft.fftshift(FFT_R1_ori)
FREQ0 = np.fft.fftshift(FREQ0) FREQ0 = np.fft.fftshift(FREQ0)
################ reject samples above cutoff ################## ################ reject samples above cutoff ##################
if n_remove !=0: if n_remove !=0:
FFT_R0_ori = FFT_R0_ori[n_remove:-n_remove] FFT_R0_ori = FFT_R0_ori[n_remove:-n_remove]
...@@ -82,11 +82,11 @@ class source_separation(object): ...@@ -82,11 +82,11 @@ class source_separation(object):
# print('len(ids1[ids1_check]), len(ids1)',len(ids1[ids1_check]), len(ids1)) # print('len(ids1[ids1_check]), len(ids1)',len(ids1[ids1_check]), len(ids1))
if len(ids0[ids0_check]) < len(ids0): if len(ids0[ids0_check]) < len(ids0):
ids0 = ids0[ids0_check] ids0 = ids0[ids0_check]
if len(ids1[ids1_check]) < len(ids1): if len(ids1[ids1_check]) < len(ids1):
ids1 = ids1[ids1_check] ids1 = ids1[ids1_check]
################### how many signal components in R0 ################## ################### how many signal components in R0 ##################
idx0_diff = np.diff(ids0,n=1) idx0_diff = np.diff(ids0,n=1)
...@@ -100,48 +100,48 @@ class source_separation(object): ...@@ -100,48 +100,48 @@ class source_separation(object):
################# find the number of singal components ################ ################# find the number of singal components ################
if len(idx0_comp)>=len(idx1_comp): # detected signal components if len(idx0_comp)>=len(idx1_comp): # detected signal components
idx_comp = idx0_comp idx_comp = idx0_comp
ids = ids0 ids = ids0
else: else:
idx_comp = idx1_comp idx_comp = idx1_comp
ids = ids1 ids = ids1
if not len(idx_comp): # only one signal component--no need for division if not len(idx_comp): # only one signal component--no need for division
SS_list = [self.rx_fft] SS_list = [self.rx_fft]
self.cfreq_bin.append(self.Center_freq) self.cfreq_bin.append(self.Center_freq)
elif len(idx_comp)==1: # Two signal components elif len(idx_comp)==1: # Two signal components
bin_freq = FREQ0[np.argmin(FFT_R0_ori[ ids[idx_comp[0]]:ids[idx_comp[0]+1] ]) + ids[idx_comp[0]]] bin_freq = FREQ0[np.argmin(FFT_R0_ori[ ids[idx_comp[0]]:ids[idx_comp[0]+1] ]) + ids[idx_comp[0]]]
bin_line = np.argmin(np.abs(rx_freq-bin_freq)) bin_line = np.argmin(np.abs(rx_freq-bin_freq))
# if self.debug: # if self.debug:
# print('bin_line',bin_line) # print('bin_line',bin_line)
SS_list = [np.vstack((self.rx_fft[0,0:bin_line], self.rx_fft[1,0:bin_line])), \ SS_list = [np.vstack((self.rx_fft[0,0:bin_line], self.rx_fft[1,0:bin_line])), \
np.vstack((self.rx_fft[0,bin_line:len(self.rx_fft[0,:])], \ np.vstack((self.rx_fft[0,bin_line:len(self.rx_fft[0,:])], \
self.rx_fft[1,bin_line:len(self.rx_fft[0,:])]))] self.rx_fft[1,bin_line:len(self.rx_fft[0,:])]))]
self.cfreq_bin.append(rx_freq[int(bin_line/2)] + self.Center_freq) self.cfreq_bin.append(rx_freq[int(bin_line/2)] + self.Center_freq)
self.cfreq_bin.append(rx_freq[int((bin_line+self.num_sampes-1)/2)] + self.Center_freq) self.cfreq_bin.append(rx_freq[int((bin_line+self.num_sampes-1)/2)] + self.Center_freq)
else: # more than two signal components else: # more than two signal components
bin_line = [] bin_line = []
for idd in idx_comp: for idd in idx_comp:
bin_freq = FREQ0[np.argmin(FFT_R0_ori[ ids[idd]:ids[idd+1] ]) + ids[idd]] bin_freq = FREQ0[np.argmin(FFT_R0_ori[ ids[idd]:ids[idd+1] ]) + ids[idd]]
bin_line.append(np.argmin(np.abs(rx_freq-bin_freq))) bin_line.append(np.argmin(np.abs(rx_freq-bin_freq)))
# if self.debug: # if self.debug:
# print('bin_line, partitions',bin_line, len(bin_line)+1) # print('bin_line, partitions',bin_line, len(bin_line)+1)
SS_list = [np.vstack((self.rx_fft[0,0:bin_line[0]], self.rx_fft[1,0:bin_line[0]]))] SS_list = [np.vstack((self.rx_fft[0,0:bin_line[0]], self.rx_fft[1,0:bin_line[0]]))]
self.cfreq_bin.append(rx_freq[int(bin_line[0]/2)] + self.Center_freq) self.cfreq_bin.append(rx_freq[int(bin_line[0]/2)] + self.Center_freq)
for n in range(len(bin_line)-1): for n in range(len(bin_line)-1):
SS_list.append( np.vstack((self.rx_fft[0,bin_line[n]:bin_line[n+1]], \ SS_list.append( np.vstack((self.rx_fft[0,bin_line[n]:bin_line[n+1]], \
self.rx_fft[1,bin_line[n]:bin_line[n+1]])) ) self.rx_fft[1,bin_line[n]:bin_line[n+1]])) )
self.cfreq_bin.append(rx_freq[int((bin_line[n]+bin_line[n+1])/2)] + self.Center_freq) self.cfreq_bin.append(rx_freq[int((bin_line[n]+bin_line[n+1])/2)] + self.Center_freq)
SS_list.append(np.vstack((self.rx_fft[0,bin_line[-1]:len(self.rx_fft[0,:])], \ SS_list.append(np.vstack((self.rx_fft[0,bin_line[-1]:len(self.rx_fft[0,:])], \
self.rx_fft[1,bin_line[-1]:len(self.rx_fft[0,:])]))) self.rx_fft[1,bin_line[-1]:len(self.rx_fft[0,:])])))
self.cfreq_bin.append(rx_freq[int((bin_line[-1]+self.num_sampes-1)/2)] + self.Center_freq) self.cfreq_bin.append(rx_freq[int((bin_line[-1]+self.num_sampes-1)/2)] + self.Center_freq)
return SS_list return SS_list
...@@ -191,10 +191,10 @@ class source_separation(object): ...@@ -191,10 +191,10 @@ class source_separation(object):
# print('idx_highest', idx_highest) # print('idx_highest', idx_highest)
if idx_highest%2: if idx_highest%2:
A_temp = np.array([[0,1],[1,0]]) @ A_temp A_temp = np.array([[0,1],[1,0]]) @ A_temp
SShat = np.vstack((SShat[1,:],SShat[0,:])) SShat = np.vstack((SShat[1,:],SShat[0,:]))
else: else:
pass pass
self.mix_matrix.append(A_temp) self.mix_matrix.append(A_temp)
if self.debug: if self.debug:
...@@ -292,7 +292,7 @@ class source_separation(object): ...@@ -292,7 +292,7 @@ class source_separation(object):
sep_samp0 = np.reshape(real_img0, -1, order='F') sep_samp0 = np.reshape(real_img0, -1, order='F')
sep_samp0 = sep_samp0.reshape(-1,1) sep_samp0 = sep_samp0.reshape(-1,1)
a = array(sep_samp0,'float32') a = np.array(sep_samp0,'float32')
output_file = open('sep_sample0.txt', 'wb') output_file = open('sep_sample0.txt', 'wb')
a.tofile(output_file) a.tofile(output_file)
output_file.close() output_file.close()
...@@ -301,7 +301,7 @@ class source_separation(object): ...@@ -301,7 +301,7 @@ class source_separation(object):
sep_samp1 = np.reshape(real_img1, -1, order='F') sep_samp1 = np.reshape(real_img1, -1, order='F')
sep_samp1 = sep_samp1.reshape(-1,1) sep_samp1 = sep_samp1.reshape(-1,1)
a = array(sep_samp1,'float32') a = np.array(sep_samp1,'float32')
output_file = open('sep_sample1.txt', 'wb') output_file = open('sep_sample1.txt', 'wb')
a.tofile(output_file) a.tofile(output_file)
output_file.close() output_file.close()
...@@ -345,11 +345,11 @@ class source_separation(object): ...@@ -345,11 +345,11 @@ class source_separation(object):
print('main_raw',main_raw,'\n') print('main_raw',main_raw,'\n')
if main_raw!=main_ss: if main_raw!=main_ss:
for m in range(len(self.cfreq_bin)): for m in range(len(self.cfreq_bin)):
self.mix_matrix[m] = np.array([[0,1],[1,0]]) @ self.mix_matrix[m] self.mix_matrix[m] = np.array([[0,1],[1,0]]) @ self.mix_matrix[m]
sep_db = np.vstack((esti1,esti0)) sep_db = np.vstack((esti1,esti0))
else: else:
sep_db = np.vstack((esti0,esti1)) sep_db = np.vstack((esti0,esti1))
if issave: if issave:
# get mixing matrix # get mixing matrix
......