def main(samples, symbols, adc_rate, dac_rate, baudrate, tx_symbol_length, span_length, span_param): span = Fiber(length=span_length, reference_wavelength=1550, slope=0, **span_param) sylen = tx_symbol_length * (baudrate / dac_rate) sylen = int(np.ceil(sylen)) signal = Signal(baudrate, samples, symbols, adc_rate, wavelength=1550e-9) signal[:] = remove_dc(signal[:]) signal[:] = signal[:] / np.sqrt( np.mean(np.abs(signal[:])**2, axis=-1, keepdims=True)) signal.samples = resampy.resample(signal.samples, signal.fs / signal.baudrate, 2) signal[:] = orthonormalize_signal(signal[:], os=1) signal.fs = 2 * signal.baudrate signal.tx_symbols = signal.tx_symbols[:, :sylen] # cdc signal = cd_compensation(span, signal, signal.fs) # freq_comp = FrequencyOffsetComp(8, True) signal = freq_comp.prop(signal) print(freq_comp.freq_offset) signals = find_each_section( signal, total_length=int(np.floor(len(signal) / sylen / 2)) - 1, symbol_length=sylen) for signal in signals: signal = batch_equlization(signal) return signals
def prop(self,signal:Signal)->Signal: self.const = signal.constl res,res_symbol = self.__divide_signal_into_block(signal) self.block_number = len(res[0]) for row_samples,row_symbols in zip(res,res_symbol): phase_noise,cpr_temp_symbol,symbol_for_snr = self.__prop_one_pol(row_samples,row_symbols) self.cpr_symbol.append(cpr_temp_symbol) self.symbol_for_snr.append(symbol_for_snr) self.phase_noise.append(phase_noise) signal.samples = np.array(self.cpr_symbol) signal.tx_symbols = np.array(self.symbol_for_snr) self.cpr_symbol = np.array(self.cpr_symbol) self.symbol_for_snr = np.array(self.symbol_for_snr) return signal
def prop(self,signal:Signal) -> Signal: from .dsp_tools import _segment_axis from .dsp_tools import get_time_vector length = len(signal)// self.group freq_offset = [] if length * self.group != signal.shape[1]: import warnings warnings.warn("The group can not be divided into integers and some points will be discarded") time_vector = get_time_vector(len(signal), signal.fs) time_vector = np.atleast_2d(time_vector)[0] last_point = 0 xpol = _segment_axis(signal[0], length, 0) ypol = _segment_axis(signal[1], length, 0) time_vector_segment = time_vector[:length] phase = np.zeros_like(xpol) for idx, (xpol_row, ypol_row) in enumerate(zip(xpol, ypol)): array = np.array([xpol_row, ypol_row]) freq = find_freq_offset(array, signal.fs, fft_size=2**18) phase[idx] = 2 * np.pi * freq * time_vector_segment + last_point freq_offset.append(freq) last_point = phase[idx, -1] if self.apply: xpol = xpol * np.exp(-1j * phase) ypol = ypol * np.exp(-1j * phase) xpol = xpol.flatten() ypol = ypol.flatten() signal.samples = np.array([xpol,ypol]) self.freq_offset = freq_offset return signal
def __init__(self, baudrate, adc_rate, samples, tx_symbols, tx_length, **param_dict): ''' :param baudrate: The baudrate of the received signal [hz] :param adc_rate: The sampling rate of the scope in [hz] :param samples: The received samples of the signal :param tx_length: The propagation length of the signal in KM :param param_dict: :key: ntaps: The ntaps for the LMS_equalizater ''' signal = Signal(baudrate, samples, tx_symbols, adc_rate, wavelength=1550e-9) self.signal = signal self.span = Fiber(alpha=0.2, D=16.7, length=tx_length, reference_wavelength=1550, slope=0) self.param = param_dict self.dsp_processed_signals = [] self.snrs = [] self.average_symbols_signal = None
def average_over_symbol(signals:[Signal]) -> Signal: if len(signals) ==0: return xpol = 0 ypol = 0 for signal in signals: xpol = xpol + signal[0] ypol = ypol + signal[1] xpol = xpol/len(signals) ypol = ypol/len(signals) samples = np.vstack((xpol,ypol)) signal = Signal(signals[0].baudrate,samples,signals[0].tx_symbols,signals[0].fs,signals[0].wavelength) return signal
def find_each_section(signal, total_length, symbol_length,is_visable): # 2e6 ----5 被采样,降到2倍采样 out, corr_res = syncsignal(signal.tx_symbols, signal.samples, 2, is_visable) signals = [] for i in range(total_length): signals.append(Signal(signal.baudrate, out[:, :symbol_length * signal.sps], signal.tx_symbols, signal.fs, signal.wavelength)) try: out = out[:, symbol_length * signal.sps:] out, _ = syncsignal(signal.symbol, out, signal.sps, is_visable) except Exception as e: return signals return signals
def matched_filter(signal: Signal, roll_off) -> Signal: samples = np.copy(signal[:]) for row in samples: row[:] = rrcos_pulseshaping_freq(row, signal.fs, 1 / signal.baudrate, roll_off) return Signal(signal.baudrate, samples, signal.tx_symbols, signal.fs, signal.wavelength)