rjw | 6c1fd8f | 2022-11-30 14:33:01 +0800 | [diff] [blame] | 1 | import numpy as np
|
| 2 | import matplotlib.pyplot as plt
|
| 3 | from mpl_toolkits.axes_grid1 import make_axes_locatable
|
| 4 | from matplotlib.ticker import MultipleLocator
|
| 5 |
|
| 6 | from pylab import *
|
| 7 |
|
| 8 | ######################################################################################
|
| 9 | # ----------------------------------- NR PLOTTING (B) -------------------------------#
|
| 10 | ######################################################################################
|
| 11 | class NR_Plot:
|
| 12 | def __init__(self, params):
|
| 13 | self.rows = 2
|
| 14 | self.cols = 3
|
| 15 | self.fig = plt.figure(figsize=(20,10),dpi=80)
|
| 16 | self.fig.set_facecolor('black')
|
| 17 |
|
| 18 | self.params = params
|
| 19 | self.ssb_idx = 0
|
| 20 |
|
| 21 | def timedomain_plot(self, timedomain_IQ):
|
| 22 | time_vec = (1/self.params.sample_rate)*np.arange(len(timedomain_IQ))
|
| 23 | ax = plt.subplot(self.rows, self.cols, 1)
|
| 24 | ax.set_facecolor('black')
|
| 25 | ax.set_title("Time domain IQ", fontsize=16, color='white')
|
| 26 | ax.plot(time_vec,np.real(timedomain_IQ), 'cyan', ms=0.)
|
| 27 | ax.plot(time_vec,np.imag(timedomain_IQ), 'purple', ms=0.)
|
| 28 | ax.yaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 29 | ax.xaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 30 | ax.spines['bottom'].set_color('white')
|
| 31 | ax.spines['top'].set_color('white')
|
| 32 | ax.spines['right'].set_color('white')
|
| 33 | ax.spines['left'].set_color('white')
|
| 34 | ax.tick_params(axis='x', colors='white')
|
| 35 | ax.tick_params(axis='y', colors='white')
|
| 36 | ax.set_xlim(time_vec[0], time_vec[-1])
|
| 37 | ymin, ymax = ax.get_ylim()
|
| 38 | ax.set_xlabel('Time progression (ms)', color='white')
|
| 39 | ax.set_ylabel('Amplitude', color='white')
|
| 40 |
|
| 41 | legend = ax.legend(('I-component','Q-component'), loc='upper center', bbox_to_anchor=(0.5, 1.0),ncol='2')
|
| 42 | frame = legend.get_frame()
|
| 43 | frame.set_facecolor('black')
|
| 44 | frame.set_edgecolor('white')
|
| 45 | for text in legend.get_texts():
|
| 46 | plt.setp(text, color = 'white')
|
| 47 | plt.setp(text, fontsize='12')
|
| 48 |
|
| 49 | def freqdomain_plot(self, timedomain_IQ):
|
| 50 | Accum_freqSpectrum_IQ_shifted_main = [0]* len(timedomain_IQ)
|
| 51 |
|
| 52 | # Frequency Span vector
|
| 53 | Fs = self.params.sample_rate
|
| 54 | N = len(timedomain_IQ)
|
| 55 | dF = Fs/N
|
| 56 | Accum_slidingWinMat_freqSpectrum_IQ_shifted_main = np.zeros((len(timedomain_IQ), self.params.num_avg_frames))
|
| 57 |
|
| 58 | f_vec = np.arange(-Fs/2,Fs/2,dF)
|
| 59 |
|
| 60 | ax = plt.subplot(self.rows, self.cols, 4)
|
| 61 | ax.set_facecolor('black')
|
| 62 | ax.yaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 63 | ax.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 64 | ax.spines['bottom'].set_color('white')
|
| 65 | ax.spines['top'].set_color('white')
|
| 66 | ax.spines['right'].set_color('white')
|
| 67 | ax.spines['left'].set_color('white')
|
| 68 | ax.tick_params(axis='x', colors='white')
|
| 69 | ax.tick_params(axis='y', colors='white')
|
| 70 | ax.set_title('Frequency Spectrum',fontsize=14, color='white')
|
| 71 | ax.set_xlabel('Frequency (MHz)',fontsize=11, color='white')
|
| 72 | ax.set_ylabel('Power (dB)',fontsize=11, color='white')
|
| 73 |
|
| 74 | # Compute FFT - Freq. Spectrum
|
| 75 | freqSpectrum_IQ_main = (1.0 / self.params.analysis_frame_len) * np.fft.fft(timedomain_IQ)
|
| 76 |
|
| 77 | # Center Freq. Spectrum at 0 Hz
|
| 78 | freqSpectrum_IQ_shifted_main = np.fft.fftshift(freqSpectrum_IQ_main)
|
| 79 |
|
| 80 | if (self.params.is_averagedFrames): # Reduce variance of a signal
|
| 81 | if (self.params.is_avgSlidingWindow):
|
| 82 | # MAIN
|
| 83 | Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,1:] = Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,:-1]
|
| 84 | Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,0] = np.absolute(freqSpectrum_IQ_shifted_main)
|
| 85 | Accum_slidingWinVec_freqSpectrum_IQ_shifted_main = (1.0 / self.params.num_avg_frames) * Accum_slidingWinMat_freqSpectrum_IQ_shifted_main.sum(axis=1)
|
| 86 |
|
| 87 | ax.plot(f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'red',
|
| 88 | f_vec, 20.0*np.log10(Accum_slidingWinVec_freqSpectrum_IQ_shifted_main), 'orange')
|
| 89 | legendNames = ['Shifted at center freq', 'Avg sliding window']
|
| 90 | else:
|
| 91 | # MAIN/DIV
|
| 92 | Accum_freqSpectrum_IQ_shifted_main = self.Accum_freqSpectrum_IQ_shifted_main + np.absolute(freqSpectrum_IQ_shifted_main)
|
| 93 |
|
| 94 | ax.plot(self.f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'red',
|
| 95 | self.f_vec, 20.0*np.log10(Accum_freqSpectrum_IQ_shifted_main/frame_counter), 'orange')
|
| 96 |
|
| 97 | legendNames = ['Main', 'Avg']
|
| 98 | else:
|
| 99 | ax.plot(self.f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'y')
|
| 100 | legendNames = ['Main']
|
| 101 |
|
| 102 | legend = ax.legend((legendNames), loc=1, bbox_to_anchor=(0.5, 1.0), borderaxespad=0.)
|
| 103 | frame = legend.get_frame()
|
| 104 | frame.set_facecolor('black')
|
| 105 | frame.set_edgecolor('white')
|
| 106 | for text in legend.get_texts():
|
| 107 | plt.setp(text, color = 'w')
|
| 108 | plt.setp(text, fontsize='small')
|
| 109 |
|
| 110 | ylimit = np.max(np.ceil(np.absolute(20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)))))
|
| 111 | ax.set_ylim([-150, ylimit+10])
|
| 112 | ax.set_xlim(self.params.interp_freqSpectrum_lowLimit, self.params.interp_freqSpectrum_upperLimit)
|
| 113 | ax.yaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 114 | ax.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 115 | ax.set_title('Frequency Spectrum',fontsize=14, color='white')
|
| 116 | ax.set_xlabel('Frequency (Hz)',fontsize=11, color='white')
|
| 117 | ax.set_ylabel('Power (dB)',fontsize=11, color='white')
|
| 118 |
|
| 119 | def ss_plot(self, ss_results):
|
| 120 |
|
| 121 | # ------------------ PSS PLOT PROCESSING INIT (B) ------------------
|
| 122 | PSS_corr_magSQR_output_frame_main = ss_results.PSS_corr_magSQR_output_frame_main # Correlation result
|
| 123 | pss_time = len(PSS_corr_magSQR_output_frame_main)
|
| 124 | PSS_time_vec_tot = (1/self.params.sample_rate)*np.arange(pss_time)
|
| 125 | # ------------------ PSS PLOT PROCESSING INIT (E) ------------------
|
| 126 |
|
| 127 | # ------------------ SSS PLOT PROCESSING INIT (B) ------------------
|
| 128 | SSS_corr_magSQR_output_frame_main = ss_results.SSS_corr_magSQR_output_frame_main
|
| 129 | sss_time = len(SSS_corr_magSQR_output_frame_main)
|
| 130 | SSS_time_vec_tot = (1/self.params.sample_rate)*np.arange(sss_time)
|
| 131 | # ------------------ SSS PLOT PROCESSING INIT (E) ------------------
|
| 132 |
|
| 133 | ax = plt.subplot(self.rows, self.cols, 2)
|
| 134 | ax.set_facecolor('black')
|
| 135 | ax.yaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 136 | ax.xaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 137 | ax.spines['bottom'].set_color('white')
|
| 138 | ax.spines['top'].set_color('white')
|
| 139 | ax.spines['right'].set_color('white')
|
| 140 | ax.spines['left'].set_color('white')
|
| 141 | ax.tick_params(axis='x', colors='white')
|
| 142 | ax.tick_params(axis='y', colors='white')
|
| 143 |
|
| 144 | ax.plot(PSS_time_vec_tot, PSS_corr_magSQR_output_frame_main,'-', ms=3.0)
|
| 145 | ax.plot(SSS_time_vec_tot, SSS_corr_magSQR_output_frame_main,'.-', color='orangered', ms=2.0)
|
| 146 |
|
| 147 | ax.set_xlim([PSS_time_vec_tot[0], PSS_time_vec_tot[-1]])
|
| 148 | ax.set_ylim([0.0, 1.0])
|
| 149 | ax.xaxis.grid(True, linestyle=':', which='major', color='black',alpha=0.5)
|
| 150 |
|
| 151 | legend = ax.legend(('PSS', 'SSS'), loc='upper center', bbox_to_anchor=(0.5, 1.0),ncol='2', fontsize = 'large')
|
| 152 | frame = legend.get_frame()
|
| 153 | frame.set_facecolor('white')
|
| 154 | frame.set_edgecolor('black')
|
| 155 | for text in legend.get_texts():
|
| 156 | plt.setp(text, color = 'black')
|
| 157 | plt.setp(text, fontsize='large')
|
| 158 |
|
| 159 | ax.set_xlim([PSS_time_vec_tot[0], PSS_time_vec_tot[-1]])
|
| 160 | ax.set_ylim([0.0, 1.0])
|
| 161 | ax.xaxis.grid(True, linestyle=':', which='major', color='black',alpha=0.5)
|
| 162 |
|
| 163 | ax.set_title('PSS/SSS Correlation Outputs',fontsize=14, color='white')
|
| 164 | ax.set_xlabel('Time progression (sec.)',fontsize=14, color='white')
|
| 165 | ax.set_ylabel('Amplitude',fontsize=14, color='white')
|
| 166 |
|
| 167 | def resourceGrid_plot(self, half_frame2D_FD_occupiedRB):
|
| 168 | sizeRB = 12
|
| 169 | Y = np.arange(0, sizeRB*self.params.numRB)
|
| 170 | X = np.arange(0, self.params.symAmount*5)
|
| 171 | X, Y = np.meshgrid(X, Y)
|
| 172 |
|
| 173 | symAmount = self.params.symAmount
|
| 174 | symAmount_5ms = 5*symAmount
|
| 175 |
|
| 176 | ax = plt.subplot(self.rows, self.cols, 3)
|
| 177 | ax.set_facecolor('black')
|
| 178 | ax.spines['bottom'].set_color('white')
|
| 179 | ax.spines['top'].set_color('white')
|
| 180 | ax.spines['right'].set_color('white')
|
| 181 | ax.spines['left'].set_color('white')
|
| 182 | ax.tick_params(axis='x', colors='white')
|
| 183 | ax.tick_params(axis='y', colors='white')
|
| 184 | colorbar_divider = make_axes_locatable(ax)
|
| 185 | cb_axes = colorbar_divider.append_axes("right", size="5%", pad=1.0)
|
| 186 | ax.set_title('Five Subframes Resource Grid (Amplitude)',fontsize=14, color='white')
|
| 187 | ax.set_xlabel('OFDM symbol index',fontsize=12, color='white')
|
| 188 | ax.set_ylabel('Subcarrier index',fontsize=12, color='white')
|
| 189 | startSym = 0
|
| 190 |
|
| 191 | ax.cla()
|
| 192 | Z = np.absolute(half_frame2D_FD_occupiedRB)
|
| 193 | im = ax.imshow(Z,
|
| 194 | interpolation='nearest',
|
| 195 | cmap="nipy_spectral",
|
| 196 | aspect='auto',
|
| 197 | origin="lower",
|
| 198 | vmin=0.0, vmax=20.0)
|
| 199 |
|
| 200 | major_ticks = np.arange(-0.5, symAmount_5ms+1, symAmount)
|
| 201 | minor_ticks = np.arange(-0.5, symAmount_5ms+1, 1)
|
| 202 | ax.set_xticks(major_ticks)
|
| 203 | ax.set_xticks(minor_ticks, minor=True)
|
| 204 | ax.set_xticklabels(np.arange(startSym, symAmount_5ms+startSym+1, symAmount), fontsize=12)
|
| 205 |
|
| 206 | ax.xaxis.grid(b=True, linestyle='-', which='major', color='black',alpha=1.0)
|
| 207 | ax.xaxis.grid(b=True, linestyle=':', which='minor', color='black',alpha=0.5)
|
| 208 | ax.set_xlim([-0.5, symAmount_5ms-0.5])
|
| 209 | ax.set_ylim([-0.5, 240-0.5])
|
| 210 |
|
| 211 | ax.set_title('Five Subframes Resource Grid (Amplitude)',fontsize=14, color='white')
|
| 212 | ax.set_xlabel('OFDM symbol index', fontsize=12, color='white')
|
| 213 | ax.set_ylabel('Subcarrier index', fontsize=12, color='white')
|
| 214 |
|
| 215 | grid_colorbar = plt.colorbar(im, cax=cb_axes, ticks=MultipleLocator(1.0), format="%.1f")
|
| 216 | grid_colorbar_obj = plt.getp(grid_colorbar.ax.axes, 'yticklabels')
|
| 217 | plt.setp(grid_colorbar_obj, color='white')
|
| 218 |
|
| 219 |
|
| 220 | def constellation(self, pbchSymbols, detected_PBCH, place):
|
| 221 |
|
| 222 | ax = plt.subplot(self.rows, self.cols, place)
|
| 223 |
|
| 224 | ax.set_facecolor('black')
|
| 225 | ax.spines['bottom'].set_color('white')
|
| 226 | ax.spines['top'].set_color('white')
|
| 227 | ax.spines['right'].set_color('white')
|
| 228 | ax.spines['left'].set_color('white')
|
| 229 | ax.tick_params(axis='x', colors='white')
|
| 230 | ax.tick_params(axis='y', colors='white')
|
| 231 | ax.set_xlabel('In-phase',fontsize=10, color='white')
|
| 232 | ax.set_ylabel('Quadrature-phase',fontsize=10, color='white')
|
| 233 | colors = ['red', 'green', 'blue', 'white', 'magenta','orange','cyan','pink', 'red', 'green', 'blue', 'white', 'magenta','orange','cyan','pink']
|
| 234 |
|
| 235 | idx_first_PBCHsym = 0
|
| 236 | idx_last_PBCHsym = 432
|
| 237 | for i in xrange(detected_PBCH):
|
| 238 | line1 = ax.scatter(np.real(pbchSymbols[idx_first_PBCHsym:idx_last_PBCHsym]),np.imag(pbchSymbols[idx_first_PBCHsym:idx_last_PBCHsym]),
|
| 239 | color=colors[i],label='PBCH-QPSK'+str(self.ssb_idx),s=10,facecolors='none')
|
| 240 | idx_first_PBCHsym = idx_last_PBCHsym
|
| 241 | idx_last_PBCHsym = idx_first_PBCHsym + 432
|
| 242 | self.ssb_idx = self.ssb_idx + 1
|
| 243 |
|
| 244 | if len(pbchSymbols) == 0:
|
| 245 | return 0
|
| 246 | else:
|
| 247 | limit = np.max(np.ceil(np.absolute(pbchSymbols)))
|
| 248 | ax.set_xlim([-limit, limit])
|
| 249 | ax.set_ylim([-limit, limit])
|
| 250 |
|
| 251 | leg = ax.legend(loc='upper left', fancybox=True, shadow=True)
|
| 252 | leg.get_frame().set_alpha(0.4)
|
| 253 |
|
| 254 | lines = [line1]
|
| 255 | lined = dict()
|
| 256 | for legline, origline in zip(leg.get_lines(), lines):
|
| 257 | legline.set_picker(True) # 5 pts tolerance
|
| 258 | lined[legline] = origline
|
| 259 |
|
| 260 |
|
| 261 | def pbchDMRS_plot(self, pbchDMRS_results, amount_of_pbchDMRS):
|
| 262 |
|
| 263 | p = plt.figure(figsize=(10,6), facecolor='black')
|
| 264 | p.suptitle("PBCH DM-RS correlations (frequency domain)", fontsize = 'large', color='white')
|
| 265 |
|
| 266 | if amount_of_pbchDMRS > 8:
|
| 267 | plotting_count = 8
|
| 268 | else:
|
| 269 | plotting_count = amount_of_pbchDMRS
|
| 270 |
|
| 271 | max_ssb_candidates = 8
|
| 272 | corr_result_length = 144
|
| 273 | # init
|
| 274 | start = 0
|
| 275 | end = 144
|
| 276 | for j in xrange(1, plotting_count+1):
|
| 277 | s = plt.subplot(2, 4, j, facecolor='black')
|
| 278 | plt.subplots_adjust(hspace=0.5)
|
| 279 |
|
| 280 | maxVal = [] # Max values of correlation results
|
| 281 | for i in xrange(max_ssb_candidates):
|
| 282 | dmrsCorr = pbchDMRS_results[start:end]
|
| 283 | dmrsMaxIdx = np.argmax(dmrsCorr)
|
| 284 | peakVal = dmrsCorr[dmrsMaxIdx]
|
| 285 | maxVal.append(peakVal)
|
| 286 |
|
| 287 | s.set_xlabel('SS block index', fontsize=14, color='white')
|
| 288 | s.set_ylabel('Amplitude', fontsize=14, color='white')
|
| 289 | s.set_ylim(0.0, 0.8)
|
| 290 | s.tick_params(axis='x', colors='white')
|
| 291 | s.tick_params(axis='y', colors='white')
|
| 292 | s.spines['bottom'].set_color('white')
|
| 293 | s.spines['top'].set_color('white')
|
| 294 | s.spines['right'].set_color('white')
|
| 295 | s.spines['left'].set_color('white')
|
| 296 |
|
| 297 | start = end
|
| 298 | end = start + corr_result_length
|
| 299 |
|
| 300 | x = [0, 1, 2, 3, 4, 5, 6, 7]
|
| 301 | markerline, stemlines, baseline = stem(x, [maxVal[0], maxVal[1], maxVal[2], maxVal[3], maxVal[4], maxVal[5], maxVal[6], maxVal[7]], '-')
|
| 302 | setp(markerline, 'markerfacecolor', 'b')
|
| 303 | p.show()
|
| 304 |
|
| 305 |
|
| 306 | ######################################################################################
|
| 307 | # ----------------------------------- NR PLOTTING (B) -------------------------------#
|
| 308 | ######################################################################################
|
| 309 |
|
| 310 | ######################################################################################
|
| 311 | # --------------------------------- LTE PLOTTING (B) --------------------------------#
|
| 312 | ######################################################################################
|
| 313 |
|
| 314 | class FreqDomainPlots:
|
| 315 | def __init__ (self, params, pos):
|
| 316 |
|
| 317 | self.Accum_freqSpectrum_IQ_shifted_main = [0] * params.analysis_frame_len
|
| 318 |
|
| 319 | # Frequency Span vector
|
| 320 | Fs = params.sample_rate
|
| 321 | N = params.analysis_frame_len
|
| 322 | dF = Fs/N
|
| 323 | self.Accum_slidingWinMat_freqSpectrum_IQ_shifted_main = np.zeros( (params.analysis_frame_len,params.num_avg_frames) )
|
| 324 |
|
| 325 | self.f_vec = np.arange(-Fs/2,Fs/2,dF)
|
| 326 |
|
| 327 | self.params = params
|
| 328 | self.ax_m = plt.subplot(pos)
|
| 329 | self.ax_m.set_facecolor('black')
|
| 330 | self.ax_m.yaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 331 | self.ax_m.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 332 | self.ax_m.spines['bottom'].set_color('white')
|
| 333 | self.ax_m.spines['top'].set_color('white')
|
| 334 | self.ax_m.spines['right'].set_color('white')
|
| 335 | self.ax_m.spines['left'].set_color('white')
|
| 336 | self.ax_m.tick_params(axis='x', colors='white')
|
| 337 | self.ax_m.tick_params(axis='y', colors='white')
|
| 338 | self.ax_m.set_title('Frequency Spectrum',fontsize=14, color='white')
|
| 339 | self.ax_m.set_xlabel('Frequency (MHz)',fontsize=11, color='white')
|
| 340 | self.ax_m.set_ylabel('Power (dB)',fontsize=11, color='white')
|
| 341 |
|
| 342 | def process(self, IQ_frame_main_norm):
|
| 343 |
|
| 344 | # Compute FFT - Freq. Spectrum
|
| 345 | freqSpectrum_IQ_main = (1.0 / self.params.analysis_frame_len) * np.fft.fft(IQ_frame_main_norm)
|
| 346 |
|
| 347 | # Center Freq. Spectrum at 0 Hz
|
| 348 | freqSpectrum_IQ_shifted_main = np.fft.fftshift(freqSpectrum_IQ_main)
|
| 349 |
|
| 350 | self.ax_m.cla()
|
| 351 | if (self.params.is_averagedFrames): # Reduce variance of a signal
|
| 352 | if (self.params.is_avgSlidingWindow):
|
| 353 | # MAIN
|
| 354 | self.Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,1:] = self.Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,:-1]
|
| 355 | self.Accum_slidingWinMat_freqSpectrum_IQ_shifted_main[:,0] = np.absolute(freqSpectrum_IQ_shifted_main)
|
| 356 | self.Accum_slidingWinVec_freqSpectrum_IQ_shifted_main = (1.0 / self.params.num_avg_frames) * self.Accum_slidingWinMat_freqSpectrum_IQ_shifted_main.sum(axis=1)
|
| 357 |
|
| 358 | self.ax_m.plot(self.f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'red',
|
| 359 | self.f_vec, 20.0*np.log10(self.Accum_slidingWinVec_freqSpectrum_IQ_shifted_main), 'orange')
|
| 360 | legendNames = ['Shifted at center freq', 'Avg sliding window']
|
| 361 | else:
|
| 362 | # MAIN/DIV
|
| 363 | self.Accum_freqSpectrum_IQ_shifted_main = self.Accum_freqSpectrum_IQ_shifted_main + np.absolute(freqSpectrum_IQ_shifted_main)
|
| 364 |
|
| 365 | self.ax_m.plot(self.f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'red',
|
| 366 | self.f_vec, 20.0*np.log10(self.Accum_freqSpectrum_IQ_shifted_main/frame_counter), 'orange')
|
| 367 |
|
| 368 | legendNames = ['Main', 'Avg']
|
| 369 | else:
|
| 370 | self.ax_m.plot(self.f_vec, 20.0*np.log10(np.absolute(freqSpectrum_IQ_shifted_main)), 'y')
|
| 371 | legendNames = ['Main']
|
| 372 |
|
| 373 | legend = self.ax_m.legend((legendNames), loc=1, bbox_to_anchor=(0.5, 1.0), borderaxespad=0.)
|
| 374 | frame = legend.get_frame()
|
| 375 | frame.set_facecolor('black')
|
| 376 | frame.set_edgecolor('white')
|
| 377 | for text in legend.get_texts():
|
| 378 | plt.setp(text, color = 'w')
|
| 379 | plt.setp(text, fontsize='small')
|
| 380 |
|
| 381 | self.ax_m.set_ylim([-150, 0])
|
| 382 | self.ax_m.set_xlim(self.params.interp_freqSpectrum_lowLimit, self.params.interp_freqSpectrum_upperLimit)
|
| 383 | self.ax_m.yaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 384 | self.ax_m.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 385 | self.ax_m.set_title('Frequency Spectrum',fontsize=14, color='white')
|
| 386 | self.ax_m.set_xlabel('Frequency (Hz)',fontsize=11, color='white')
|
| 387 | self.ax_m.set_ylabel('Power (dB)',fontsize=11, color='white')
|
| 388 |
|
| 389 | def reset(self):
|
| 390 | self.Accum_freqSpectrum_IQ_shifted_main = [0] * self.params.analysis_frame_len
|
| 391 |
|
| 392 | class TimeDomainPlots:
|
| 393 | def __init__ (self, params, pos):
|
| 394 | self.time_vec_10subframes = (1/params.sample_rate)*np.arange(10*params.analysis_frame_len)
|
| 395 | self.ax_t_i_main = plt.subplot(pos)
|
| 396 | self.ax_t_i_main.set_facecolor('black')
|
| 397 | self.ax_t_i_main.yaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 398 | self.ax_t_i_main.xaxis.grid(True, linestyle=':', which='major', color='black',alpha=1.0)
|
| 399 | self.ax_t_i_main.spines['bottom'].set_color('white')
|
| 400 | self.ax_t_i_main.spines['top'].set_color('white')
|
| 401 | self.ax_t_i_main.spines['right'].set_color('white')
|
| 402 | self.ax_t_i_main.spines['left'].set_color('white')
|
| 403 | self.ax_t_i_main.tick_params(axis='x', colors='white')
|
| 404 | self.ax_t_i_main.tick_params(axis='y', colors='white')
|
| 405 | self.ax_t_i_main.set_title('Time-Domain IQ Plot',fontsize=14, color='white')
|
| 406 | self.ax_t_i_main.set_xlabel('Time progression (millisec.)',fontsize=14, color='white')
|
| 407 | self.ax_t_i_main.set_ylabel('Amplitude',fontsize=14, color='white')
|
| 408 |
|
| 409 | def process(self, IQ_full_frame_main):
|
| 410 |
|
| 411 | self.ax_t_i_main.cla()
|
| 412 | i_frame = np.real(IQ_full_frame_main)
|
| 413 | q_frame = np.imag(IQ_full_frame_main)
|
| 414 |
|
| 415 | maxValueIdx = np.argmax(i_frame)
|
| 416 | maxValue = i_frame[maxValueIdx]
|
| 417 | self.ax_t_i_main.plot(1000*self.time_vec_10subframes, i_frame,'cyan', ms=0.5)
|
| 418 | self.ax_t_i_main.plot(1000*self.time_vec_10subframes, q_frame,'purple', ms=0.5)
|
| 419 | self.ax_t_i_main.set_xlim([self.time_vec_10subframes[0], self.time_vec_10subframes[-1]])
|
| 420 | self.ax_t_i_main.set_ylim([-maxValue, maxValue])
|
| 421 | self.ax_t_i_main.set_xticks(np.arange(0, 11))
|
| 422 | self.ax_t_i_main.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=0.5)
|
| 423 | self.ax_t_i_main.set_title('Time-Domain IQ Plot', fontsize=14, color='white')
|
| 424 | self.ax_t_i_main.set_xlabel('Time progression (millisec.)',fontsize=14, color='white')
|
| 425 | self.ax_t_i_main.set_ylabel('Amplitude', fontsize=14, color='white')
|
| 426 |
|
| 427 | legend = self.ax_t_i_main.legend(('I-component','Q-component'), loc='upper center', bbox_to_anchor=(0.5, 1.0),ncol='2')
|
| 428 | frame = legend.get_frame()
|
| 429 | frame.set_facecolor('black')
|
| 430 | frame.set_edgecolor('white')
|
| 431 | for text in legend.get_texts():
|
| 432 | plt.setp(text, color = 'white')
|
| 433 | plt.setp(text, fontsize='12')
|
| 434 |
|
| 435 | class PssCorrPlots:
|
| 436 | def __init__ (self, params, pos):
|
| 437 | self.params = params
|
| 438 | self.frame_len = params.analysis_frame_len
|
| 439 | self.ax_pss_main = plt.subplot(pos)
|
| 440 | self.ax_pss_main.set_facecolor('black')
|
| 441 | self.ax_pss_main.yaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 442 | self.ax_pss_main.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=1.0)
|
| 443 | self.ax_pss_main.spines['bottom'].set_color('white')
|
| 444 | self.ax_pss_main.spines['top'].set_color('white')
|
| 445 | self.ax_pss_main.spines['right'].set_color('white')
|
| 446 | self.ax_pss_main.spines['left'].set_color('white')
|
| 447 | self.ax_pss_main.tick_params(axis='x', colors='white')
|
| 448 | self.ax_pss_main.tick_params(axis='y', colors='white')
|
| 449 | self.ax_pss_main.set_title('PSS/SSS Correlation Outputs',fontsize=14, color='white')
|
| 450 | self.ax_pss_main.set_xlabel('Time progression (millisec.)',fontsize=14, color='white')
|
| 451 | self.ax_pss_main.set_ylabel('Amplitude',fontsize=14, color='white')
|
| 452 | self.params = params
|
| 453 |
|
| 454 | # LTE
|
| 455 | def process(self, pss):
|
| 456 |
|
| 457 | PSS_time_vec_tot = (1/self.params.sample_rate)*np.arange(self.params.analysis_frame_len*10)
|
| 458 | PSS_corr_magSQR_output_frame_main = pss.PSS_corr_magSQR_output_frame_main
|
| 459 | PSS_peak_detected = pss.PSS_peak_detected
|
| 460 | PSS_Subframe_max_idx = pss.PSS_Subframe_max_idx
|
| 461 | PSS_Subframe_max_val = pss.PSS_Subframe_max_val
|
| 462 |
|
| 463 | SSS_corr_magSQR_output_frame_main = pss.SSS_corr_magSQR_output_frame_main
|
| 464 | SSS_peak_detected = pss.SSS_peak_detected
|
| 465 | SSS_Subframe_max_idx = pss.SSS_Subframe_max_idx
|
| 466 | SSS_Subframe_max_val = pss.SSS_Subframe_max_val
|
| 467 |
|
| 468 | self.ax_pss_main.cla()
|
| 469 | self.ax_pss_main.plot(1000*PSS_time_vec_tot,PSS_corr_magSQR_output_frame_main,'.-', color='green', ms=2.0)
|
| 470 | self.ax_pss_main.plot(1000*PSS_time_vec_tot,SSS_corr_magSQR_output_frame_main,'.-', color='lightgreen', ms=2.0)
|
| 471 |
|
| 472 | if (PSS_peak_detected == 1):
|
| 473 | peak_idx = (1/self.params.sample_rate)*(9*self.params.analysis_frame_len+PSS_Subframe_max_idx)
|
| 474 | self.ax_pss_main.plot(1000*peak_idx,PSS_Subframe_max_val,marker="o", color='red', ms=10.0)
|
| 475 | if (SSS_peak_detected == 1):
|
| 476 | peak_idx = (1/self.params.sample_rate)*(9*self.params.analysis_frame_len+SSS_Subframe_max_idx)
|
| 477 | self.ax_pss_main.plot(1000*peak_idx,SSS_Subframe_max_val,marker="o", color='pink', ms=10.0)
|
| 478 |
|
| 479 | self.ax_pss_main.set_xlim([PSS_time_vec_tot[0], PSS_time_vec_tot[-1]])
|
| 480 | self.ax_pss_main.set_yticklabels(fontsize=20)
|
| 481 |
|
| 482 | self.ax_pss_main.set_ylim([0.0,0.5])
|
| 483 | self.ax_pss_main.set_xticks([0.0,0.0010666,0.0021332,0.0031998,0.00426641,0.00533301,0.00639961,0.00746621,0.00853281,0.00959941,0.01066602])
|
| 484 |
|
| 485 | self.ax_pss_main.xaxis.grid(True, linestyle=':', which='major', color='white',alpha=0.5)
|
| 486 |
|
| 487 | self.ax_pss_main.set_title('PSS/SSS Correlation Outputs',fontsize=14, color='white')
|
| 488 | self.ax_pss_main.set_xlabel('Time progression (millisec.)',fontsize=20, color='white')
|
| 489 | self.ax_pss_main.set_ylabel('Amplitude',fontsize=20, color='white')
|
| 490 |
|
| 491 | class ResourceGrid:
|
| 492 | def __init__ (self, params, pos):
|
| 493 | sizeRB = 12
|
| 494 | Y = np.arange(0, sizeRB*params.numRB)
|
| 495 | X = np.arange(0, params.symAmount*5)
|
| 496 | X, Y = np.meshgrid(X, Y)
|
| 497 |
|
| 498 | self.symAmount = params.symAmount
|
| 499 | self.symAmount_5ms = 5*self.symAmount
|
| 500 |
|
| 501 | self.ax_5msFD_grid_main = plt.subplot(pos)
|
| 502 | self.ax_5msFD_grid_main.set_facecolor('black')
|
| 503 | self.ax_5msFD_grid_main.spines['bottom'].set_color('white')
|
| 504 | self.ax_5msFD_grid_main.spines['top'].set_color('white')
|
| 505 | self.ax_5msFD_grid_main.spines['right'].set_color('white')
|
| 506 | self.ax_5msFD_grid_main.spines['left'].set_color('white')
|
| 507 | self.ax_5msFD_grid_main.tick_params(axis='x', colors='white')
|
| 508 | self.ax_5msFD_grid_main.tick_params(axis='y', colors='white')
|
| 509 | self.colorbar_divider = make_axes_locatable(self.ax_5msFD_grid_main)
|
| 510 | self.cb_axes = self.colorbar_divider.append_axes("right", size="5%", pad=1.0)
|
| 511 | self.ax_5msFD_grid_main.set_title('Five Subframes Resource Grid (Amplitude)',fontsize=14, color='white')
|
| 512 | self.ax_5msFD_grid_main.set_xlabel('OFDM symbol index',fontsize=12, color='white')
|
| 513 | self.ax_5msFD_grid_main.set_ylabel('Subcarrier index',fontsize=12, color='white')
|
| 514 | self.startSym = 0
|
| 515 |
|
| 516 | def process(self, half_frame2D_FD_occupiedRB):
|
| 517 | self.ax_5msFD_grid_main.cla()
|
| 518 | Z = np.absolute(half_frame2D_FD_occupiedRB)
|
| 519 | im = self.ax_5msFD_grid_main.imshow(Z,
|
| 520 | interpolation='nearest',
|
| 521 | cmap="nipy_spectral",
|
| 522 | aspect='auto',
|
| 523 | origin="lower",
|
| 524 | vmin=0.0, vmax=20.0)
|
| 525 |
|
| 526 | self.startSym = 0
|
| 527 |
|
| 528 | major_ticks = np.arange(-0.5, self.symAmount_5ms+1, self.symAmount)
|
| 529 | minor_ticks = np.arange(-0.5, self.symAmount_5ms+1, 1)
|
| 530 | self.ax_5msFD_grid_main.set_xticks(major_ticks)
|
| 531 | self.ax_5msFD_grid_main.set_xticks(minor_ticks, minor=True)
|
| 532 | self.ax_5msFD_grid_main.set_xticklabels(np.arange(self.startSym, self.symAmount_5ms+self.startSym+1, self.symAmount), fontsize=12)
|
| 533 |
|
| 534 | self.ax_5msFD_grid_main.xaxis.grid(b=True, linestyle='-', which='major', color='black',alpha=1.0)
|
| 535 | self.ax_5msFD_grid_main.xaxis.grid(b=True, linestyle=':', which='minor', color='black',alpha=0.5)
|
| 536 | self.ax_5msFD_grid_main.set_xlim([-0.5, self.symAmount_5ms-0.5])
|
| 537 | self.ax_5msFD_grid_main.set_ylim([-0.5, 240-0.5])
|
| 538 |
|
| 539 | self.ax_5msFD_grid_main.set_title('Five Subframes Resource Grid (Amplitude)',fontsize=14, color='white')
|
| 540 | self.ax_5msFD_grid_main.set_xlabel('OFDM symbol index', fontsize=12, color='white')
|
| 541 | self.ax_5msFD_grid_main.set_ylabel('Subcarrier index', fontsize=12, color='white')
|
| 542 |
|
| 543 | self.grid_colorbar = plt.colorbar(im, cax=self.cb_axes, ticks=MultipleLocator(1.0), format="%.1f")
|
| 544 | self.grid_colorbar_obj = plt.getp(self.grid_colorbar.ax.axes, 'yticklabels')
|
| 545 | plt.setp(self.grid_colorbar_obj, color='white')
|
| 546 |
|
| 547 | class PilotsPlots:
|
| 548 | def __init__ (self, params, pos, idx):
|
| 549 | self.idx = idx
|
| 550 | self.ax_pilots_sf0_main = plt.subplot(pos)
|
| 551 | self.ax_pilots_sf0_main.set_facecolor('black')
|
| 552 | self.ax_pilots_sf0_main.spines['bottom'].set_color('white')
|
| 553 | self.ax_pilots_sf0_main.spines['top'].set_color('white')
|
| 554 | self.ax_pilots_sf0_main.spines['right'].set_color('white')
|
| 555 | self.ax_pilots_sf0_main.spines['left'].set_color('white')
|
| 556 | self.ax_pilots_sf0_main.tick_params(axis='x', colors='white')
|
| 557 | self.ax_pilots_sf0_main.tick_params(axis='y', colors='white')
|
| 558 |
|
| 559 | self.ax_pilots_sf0_main.set_title('IQ Raw Pilots (S'+ str(self.idx) + ')',fontsize=12, color='white')
|
| 560 | self.ax_pilots_sf0_main.set_xlabel('In-phase',fontsize=10, color='white')
|
| 561 | self.ax_pilots_sf0_main.set_ylabel('Quadrature',fontsize=10, color='white')
|
| 562 |
|
| 563 | def process(self,Pilots_5subFrames_RAW):
|
| 564 | lim_vec = [-10.0,10.0]
|
| 565 | colors_ = ['blue','green','red','cyan','yellow']
|
| 566 | add_idx = self.idx * 4
|
| 567 |
|
| 568 | self.ax_pilots_sf0_main.cla()
|
| 569 |
|
| 570 | for kk in xrange(4):
|
| 571 | self.ax_pilots_sf0_main.scatter(np.real(Pilots_5subFrames_RAW[:,add_idx+kk]),np.imag(Pilots_5subFrames_RAW[:,add_idx+kk]),color=colors_[kk], s=1.0)
|
| 572 |
|
| 573 | self.ax_pilots_sf0_main.set_aspect('equal')
|
| 574 | self.ax_pilots_sf0_main.set_xlim(lim_vec)
|
| 575 | self.ax_pilots_sf0_main.set_ylim(lim_vec)
|
| 576 | self.ax_pilots_sf0_main.set_title('IQ Raw Pilots (S'+ str(self.idx) + ')',fontsize=12, color='white')
|
| 577 | self.ax_pilots_sf0_main.set_xlabel('In-phase',fontsize=10, color='white')
|
| 578 | self.ax_pilots_sf0_main.set_ylabel('Quadrature',fontsize=10, color='white')
|
| 579 |
|
| 580 | class PilotsPhasePlots:
|
| 581 | def __init__ (self, params, pos, idx):
|
| 582 | self.idx = idx
|
| 583 | self.ax_pilots_phase_sf0_main = plt.subplot(pos)
|
| 584 | self.ax_pilots_phase_sf0_main.set_facecolor('black')
|
| 585 | self.ax_pilots_phase_sf0_main.spines['bottom'].set_color('white')
|
| 586 | self.ax_pilots_phase_sf0_main.spines['top'].set_color('white')
|
| 587 | self.ax_pilots_phase_sf0_main.spines['right'].set_color('white')
|
| 588 | self.ax_pilots_phase_sf0_main.spines['left'].set_color('white')
|
| 589 | self.ax_pilots_phase_sf0_main.tick_params(axis='x', colors='white')
|
| 590 | self.ax_pilots_phase_sf0_main.tick_params(axis='y', colors='white')
|
| 591 |
|
| 592 | self.ax_pilots_phase_sf0_main.set_title('Mag/Phase Pilots (S'+ str(self.idx) + ')',fontsize=12, color='white')
|
| 593 | self.ax_pilots_phase_sf0_main.set_xlabel('In-phase',fontsize=10, color='white')
|
| 594 | self.ax_pilots_phase_sf0_main.set_ylabel('Quadrature',fontsize=10, color='white')
|
| 595 |
|
| 596 | def process(self,CSRS_ChannelEst_RAW):
|
| 597 | lim_vec = [-10.0,10.0]
|
| 598 | colors_ = ['blue','green','red','cyan','yellow']
|
| 599 | add_idx = self.idx * 4
|
| 600 |
|
| 601 | self.ax_pilots_phase_sf0_main.cla()
|
| 602 |
|
| 603 | for kk in xrange(0,4):
|
| 604 | self.ax_pilots_phase_sf0_main.scatter(np.real(CSRS_ChannelEst_RAW[:,add_idx+kk]),np.imag(CSRS_ChannelEst_RAW[:,add_idx+kk]),color=colors_[kk], s=1.0)
|
| 605 |
|
| 606 | self.ax_pilots_phase_sf0_main.set_aspect('equal')
|
| 607 | self.ax_pilots_phase_sf0_main.set_xlim(lim_vec)
|
| 608 | self.ax_pilots_phase_sf0_main.set_ylim(lim_vec)
|
| 609 | self.ax_pilots_phase_sf0_main.set_title('Mag/Phase Pilots (S'+ str(self.idx) + ')',fontsize=12, color='white')
|
| 610 | self.ax_pilots_phase_sf0_main.set_xlabel('In-phase',fontsize=10, color='white')
|
| 611 | self.ax_pilots_phase_sf0_main.set_ylabel('Quadrature',fontsize=10, color='white')
|
| 612 |
|
| 613 | class CompensatedDataPlots:
|
| 614 | def __init__ (self, params, pos, idx):
|
| 615 | self.idx = idx
|
| 616 | self.ax_data_sf0 = plt.subplot(pos)
|
| 617 | self.ax_data_sf0.set_facecolor('black')
|
| 618 | self.ax_data_sf0.spines['bottom'].set_color('white')
|
| 619 | self.ax_data_sf0.spines['top'].set_color('white')
|
| 620 | self.ax_data_sf0.spines['right'].set_color('white')
|
| 621 | self.ax_data_sf0.spines['left'].set_color('white')
|
| 622 | self.ax_data_sf0.tick_params(axis='x', colors='white')
|
| 623 | self.ax_data_sf0.tick_params(axis='y', colors='white')
|
| 624 | if self.idx == 0:
|
| 625 | self.ax_data_sf0.set_title('IQ Scatter (Subframe 0)',fontsize=14, color='white')
|
| 626 | self.legend = self.ax_data_sf0.legend(('Slot 0','Slot 1'),loc='upper left', bbox_to_anchor=(1.0, 1.0))
|
| 627 | self.frame = self.legend.get_frame()
|
| 628 | self.frame.set_facecolor('black')
|
| 629 | self.frame.set_edgecolor('white')
|
| 630 | for text in self.legend.get_texts():
|
| 631 | plt.setp(text, color = 'w')
|
| 632 | else:
|
| 633 | self.ax_data_sf0.set_title('IQ Scatter (Subframe ' + str(idx) +')',fontsize=14, color='white')
|
| 634 | self.ax_data_sf0.set_xlabel('In-phase',fontsize=11, color='white')
|
| 635 | self.ax_data_sf0.set_ylabel('Quadrature',fontsize=11, color='white')
|
| 636 |
|
| 637 | def process (self, full_phaseComp_mat):
|
| 638 | ofdm_sym = [1,2,3,5,6]
|
| 639 | lim_vec = [-2.0,2.0]
|
| 640 |
|
| 641 | self.ax_data_sf0.cla()
|
| 642 | self.ax_data_sf0.cla()
|
| 643 | self.ax_data_sf0.cla()
|
| 644 |
|
| 645 | for kk in xrange(5):
|
| 646 | _offset_ = self.idx * 14
|
| 647 | self.ax_data_sf0.scatter(np.real(full_phaseComp_mat[:,ofdm_sym[kk]+_offset_]),np.imag(full_phaseComp_mat[:,ofdm_sym[kk]+_offset_]),color='magenta', s=1.0)
|
| 648 | _offset_ = _offset_ + 7
|
| 649 | self.ax_data_sf0.scatter(np.real(full_phaseComp_mat[:,ofdm_sym[kk]+_offset_]),np.imag(full_phaseComp_mat[:,ofdm_sym[kk]+_offset_]),color='yellow', s=1.0)
|
| 650 |
|
| 651 | self.ax_data_sf0.set_aspect('equal')
|
| 652 | self.ax_data_sf0.set_xlim(lim_vec)
|
| 653 | self.ax_data_sf0.set_ylim(lim_vec)
|
| 654 |
|
| 655 | self.ax_data_sf0.set_xlabel('In-phase',fontsize=11, color='white')
|
| 656 | self.ax_data_sf0.set_ylabel('Quadrature',fontsize=11, color='white')
|
| 657 |
|
| 658 | if self.idx == 0:
|
| 659 | self.ax_data_sf0.set_title('IQ Scatter (Subframe 0)',fontsize=14, color='white')
|
| 660 | self.legend = self.ax_data_sf0.legend(('Slot 0','Slot 1'),loc='upper left', bbox_to_anchor=(1.0, 1.0))
|
| 661 | self.frame = self.legend.get_frame()
|
| 662 | self.frame.set_facecolor('black')
|
| 663 | self.frame.set_edgecolor('white')
|
| 664 | for text in self.legend.get_texts():
|
| 665 | plt.setp(text, color = 'w')
|
| 666 | else:
|
| 667 | self.ax_data_sf0.set_title('Subframe ' + str(self.idx) ,fontsize=14, color='white')
|
| 668 |
|
| 669 |
|
| 670 | ######################################################################################
|
| 671 | # ---------------------------------- LTE PLOTTING (E) -------------------------------#
|
| 672 | ###################################################################################### |