def try_mimo_setting(df, sig, set, mset, trainingSyms, mimodir): N = set['N'] nmodes = set['nmodes'] n_training_syms = mset['n_training_syms'] lb = mset['lb'] mu = mset['mu'] nloops = mset['nloops'] ovsmpl = set['ovsmpl'] t_conv = N - 50000 t_stop = N - 1000 if mset['errorcalc'] == 'lms': print('LMS Enabled') unit = np.sqrt(2) * 0.5 constellation = [ unit + 1j * unit, unit - 1j * unit, -unit + 1j * unit, -unit - 1j * unit ] errorcalc = TrainedLMS(trainingSyms[:, :n_training_syms], constellation, lb) sig_with_loops = errorcalc.AddTrainingLoops(sig, ovsmpl, nloops) sig_Martin = sig_with_loops.copy()[:, :N + n_training_syms * nloops] mimo = FrequencyDomainBlockwizeMimo(nmodes, lb, ovsmpl, mu, errorcalc) sig_Martin[:, :], taps_Martin = mimo.equalize_signal(sig_with_loops) else: errorcalc = CMAErrorCalculator() sig_Martin = sig_with_loops.copy()[:, :N] mimo = FrequencyDomainBlockwizeMimo(nmodes, lb, ovsmpl, mu, errorcalc) sig_Martin[:, :], taps_Martin = mimo.equalize_signal(sig) print(sig_Martin.shape) #sig_Martin ,ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = [] for i_mode in range(nmodes): err_Martin_ = calculate_radius_directed_error( sig_Martin[i_mode, 0:t_stop], 1) err_Martin.append(mlab.movavg(abs(err_Martin_), movavg_taps)) try: ber_martin = calculate_BER(sig_Martin, range(t_conv, t_stop)) except: ber_martin = np.ones(nmodes) title = "Martin_mu {mu}_lb{lb}" plot_constellation(sig_Martin[:, t_conv:t_stop], title, True, mimodir) plot_error(err_Martin, title, True, mimodir) plot_taps(taps_Martin, True, mimodir) final_error_Martin = calculate_final_error(err_Martin, t_conv, t_stop) t_conv_martin = calculate_convergence(err_Martin, final_error_Martin) df_martin = UpdateDataFrame(set, mset, ber_martin, t_conv_martin, final_error_Martin, "Martin") return df.append(df_martin)
ovsmpl, sig, sig_Martin, trainingSyms = build_and_impair_signal( set, sigdir) for i_mrow, mset in mimo_settings.iterrows(): mimodir = create_dir_for_signalrow(sigdir, mimo_settings, i_mrow) if mset['errorcalc'] == 'lms': print('LMS Enabled') unit = np.sqrt(2) * 0.5 constellation = [ unit + 1j * unit, unit - 1j * unit, -unit + 1j * unit, -unit - 1j * unit ] errorcalc = TrainedLMS(trainingSyms, constellation, mset['n_training_syms'], mset['lb']) else: errorcalc = CMAErrorCalculator() mimo = FrequencyDomainBlockwizeMimo(set['nmodes'], mset['lb'], ovsmpl, mset['mu'], errorcalc) sig_Martin[:, :], taps_Martin = mimo.equalize_signal(sig) sig_Martin, ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = [] for i_mode in range(set['nmodes']): err_Martin_ = calculate_radius_directed_error( sig_Martin[i_mode, 0:t_stop], 1) err_Martin.append(mlab.movavg(abs(err_Martin_), movavg_taps)) try: ber_martin = calculate_BER(sig_Martin, range(t_conv, t_stop)) except: ber_martin = np.ones(nmodes) title = "Martin_mu" + str(mset['mu']) + "_lb" + str(mset['lb']) plot_constellation(sig_Martin[:, t_conv:t_stop], title, True, mimodir)
df = df.append(df_qampy) for mu_m in list_mu_m: for lb in list_lb: mimodir = create_dir_for_mimo_result( sigdir, mu_m, lb, "Martin") #if resample: # sig_Martin[:,:],taps_Martin = mimo_fd_ba(sig,ovsmpl= 2,lb = lb,mu = mu_m) unit = np.sqrt(2) * 0.5 constellation = [ unit + 1j * unit, unit - 1j * unit, -unit + 1j * unit, -unit - 1j * unit ] errorcalc = TrainedLMS(trainingSyms, constellation, 10000, lb) mimo = FrequencyDomainBlockwizeMimo( 2, lb, ovsmpl, mu_m, errorcalc) sig_Martin[:, :], taps_Martin = mimo.equalize_signal(sig) sig_Martin, ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = [] for i_mode in range(2): err_Martin_ = calculate_radius_directed_error( sig_Martin[i_mode, 0:t_stop], R2) err_Martin.append( mlab.movavg(abs(err_Martin_), movavg_taps)) try: ber_martin = calculate_BER(sig_Martin, range(t_conv, t_stop)) except: ber_martin = [1, 1] if produce_plots:
def test_mimo_only_accepts_complex(self): mimo = FrequencyDomainBlockwizeMimo(2) sig = np.zeros(10000).reshape(2, 5000) self.assertRaises(ValueError, mimo.equalize_signal, sig) sig.dtype = np.complex128 mimo.equalize_signal(sig)
err_Rx = calculate_radius_directed_error(sig[1],1) err_Rx = mlab.movavg(abs(err_Rx),movavg_taps) plot_request_Rx = MimoPlotRequest(err_Rx,sig.copy()[1],np.zeros(lb*2),"Recieved") # Equalisation Ntaps = 61 taps_QAMPY, err = equalisation.equalise_signal(sig, mu_Qampy, Ntaps=Ntaps, method="cma") sig_QAMPY = equalisation.apply_filter(sig, taps_QAMPY) sig_QAMPY, ph = phaserec.viterbiviterbi(sig_QAMPY, 11) sig_Martin = sig.copy()[:,:N] unit = np.sqrt(2)*0.5 constellation = [unit + 1j * unit,unit -1j*unit,-unit + 1j * unit,-unit - 1j * unit] errorcalc = TrainedLMS(trainingSyms,constellation,n_training_syms,lb) mimo = FrequencyDomainBlockwizeMimo(nmodes,lb,ovsmpl,mu_Martin,errorcalc) sig_Martin[:,:],taps_Martin = mimo.equalize_signal(sig,True) sig_Martin ,ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = calculate_radius_directed_error(sig_Martin[0][0:t_stop],1) err_Martin = mlab.movavg(abs(err_Martin),movavg_taps) err_Qampy = mlab.movavg(abs(err[1]),movavg_taps) try : print("BER_Martin = ",calculate_BER(sig_Martin,range(t_conv,t_stop))) except: print("BER failed") print("BER_Qampy = ", sig_QAMPY.cal_ber()) #plot_constellation(sig,'Origin',False)
taps_QAMPY, err = equalisation.equalise_signal(sig, mu_Qampy, Ntaps=61, method="cma") sig_QAMPY = equalisation.apply_filter(sig, taps_QAMPY) sig_QAMPY, ph = phaserec.viterbiviterbi(sig_QAMPY, 11) #if resample: # sig_Martin = sig[:,:] # even_samples = range(0,N*2,2) # sig_Martin = sig_Martin[:,even_samples] # sig_Martin,taps_Martin = mimo_cma_fd_ba(sig_Martin) #else: sig_Martin = sig.copy() mimo = FrequencyDomainBlockwizeMimo(2, lb, 1, mu_Martin, CMAErrorCalculator()) sig_Martin[:, :], taps_Martin = mimo.equalize_signal(sig) #sig_Martin ,ph = phaserec.viterbiviterbi(sig_Martin, 11) err_Martin = calculate_radius_directed_error(sig_Martin[0][0:t_stop], 1) err_Martin = mlab.movavg(abs(err_Martin), movavg_taps) err_Qampy = mlab.movavg(abs(err[1]), movavg_taps) try: print("BER_Martin = ", calculate_BER(sig_Martin, range(t_conv, t_stop))) except: print("BER failed") print("BER_Qampy = ", sig_QAMPY.cal_ber()) plot_constellation(sig, 'Origin', False)