def extract_data_sequence_schmidl(self, N, K, D, known_block, width=5): """ extracts the data_sequence from Schmidl and Cox synchronised data N - Fourier block size K - Cyclic prefix length D - length of data block following Schmidl and Cox 'block' """ correlation_arr = self.schmidl_correlate(N) index_of_max = np.argmax(np.abs(correlation_arr)) data_arr = self.get_frames_as_int16() for i in range(-width, width + 1): lower_index = index_of_max + i - K upper_index = lower_index + N + K schmidl_block = data_arr[lower_index:upper_index] h_estimate = estimate_channel(schmidl_block, known_block, N=N, K=K) mse = calc_abs_angle_error(h_estimate, N=N) print("offset: {}, mse: {}".format(i, mse)) #plot_h_freq_domain(h_estimate, N=N) data_start = index_of_max + N - 1 # can give own shift data_end = data_start + D return data_arr[data_start:data_end]
def run(): """main loop""" #constants N = int(input("N: ")) K = int(input("K: ")) # get data pre-transmission sent_file = input("Data that was sent (.wav): ") sent_file = get_recording_file_path(sent_file + ".wav") data_rec = Recording.from_file(sent_file) #sampling_freq = data_rec.rate data_seq = data_rec.get_frames_as_int16() D = len(data_seq) received_file = input("Recorded transmission (.wav): ") received_file = get_recording_file_path(received_file + ".wav") received_rec = Recording.from_file(received_file) reference_file = input("Reference signal (.wav): ") reference_file = get_recording_file_path(reference_file + ".wav") reference_rec = Recording.from_file(reference_file) offset = int(input("Manual sync offset (-ve): ")) received_data = received_rec.extract_data_sequence(reference_rec, D, offset=-offset) h = estimate_channel(received_data, data_seq, N=N, K=K) plot_h_in_time(h) plot_h_freq_domain(h, N=N)
def test_estimate_channel_simple(): rate = 1 signal = [2, 3, 1, 2, 3] filt = [1, 0, 0] N = 3 K = 2 signal_rec = Recording.from_list(signal, rate) sim_signal_rec = signal_rec.pass_through_channel(filt) sim_signal = sim_signal_rec.get_frames_as_int16()[0:N + K] h = estimate_channel(sim_signal, signal, N=N, K=K) assert np.allclose(h, filt) == True
def test_estimate_channel_hard(): rate = 1 signal = [20, 30, 10, 20, 30, 20, 30, 10, 20, 30] filt = [10, 7, 1] N = 3 K = 2 signal_rec = Recording.from_list(signal, rate) sim_signal_rec = signal_rec.pass_through_channel(filt) sim_signal = sim_signal_rec.get_frames_as_int16()[0:(N + K) * 2] h = estimate_channel(sim_signal, signal, N=N, K=K) assert np.allclose(h, filt) == True
def run(): debug_channel = False debug_symbols = False mode = input("Transmission mode (K[A,B,C]): ") K = get_K(mode) mode = input("Transmission mode (Q[1,2,3]): ") Q1, Q2 = get_Q(mode) P = N + K Q = Q2 - Q1 signal_file = input("which file would you like to decode? (no .wav required) ") signal_file = get_recording_file_path(signal_file + ".wav") signal_rec = Recording.from_file(signal_file) print("extracting packets") chirp_rec = generate_chirp_recording(F, F0, F1, C*P) packet_arr, dither_arr = signal_rec.extract_packets(chirp_rec, P) num_packets = len(packet_arr) print("\nPackets found: {}\n".format(num_packets)) print("Dither array: ") print(dither_arr) data_sequence = "" num_steps = 3 print("Decoding packets") for i in range(0, num_packets): packet = packet_arr[i] #slicing key data known_data_at_start = packet[0 : D * P] known_data_at_end = packet[- D * P : ] packet_data = packet[D * P : - D * P] #estimate channel at start known_data_pre_trans = gen_known_data_chunk(N, K) h_a = estimate_channel(known_data_at_start, known_data_pre_trans, N, K) h_b = estimate_channel(known_data_at_end, known_data_pre_trans, N, K) if debug_channel: plot_h_in_time(h_a) plot_h_in_time(h_b) plot_h_freq_domain(h_a, N) plot_h_freq_domain(h_b, N) #demodulate progress_bar(i*num_steps, num_packets*num_steps) demodulated_signal = demodulate_sequence(packet_data, h_a, h_b, N, K, Q1=Q1, Q2=Q2) if debug_symbols: plot_complex_symbols(demodulated_signal) #decode progress_bar(i*num_steps + 1, num_packets*num_steps) decoded_signal = decode_symbol_sequence(demodulated_signal) #slowest step by far #xor progress_bar(i*num_steps + 2, num_packets*num_steps) de_xored = xor(decoded_signal, Q*q) #concatenate data_sequence = data_sequence + de_xored progress_bar(num_packets*num_steps, num_packets*num_steps) decode_bit_string_jossy_format_and_save(data_sequence)