import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
from scipy.signal import correlate as corr

# Problem 3

# Load the various vectors
pas = sio.loadmat('pa_sequence.mat')
pa_sequence = pas['pa_sequence'].flatten()

rxs = sio.loadmat('rx_samples.mat')
rx_samples = rxs['rx_samples'].flatten()

# Define parameters
PAPB = int(10)  # PA sequences per symbol

# Find the beginning of the first full pa_sequence within the received
# samples. If your code works correctly, that should be at sample number
# 208.

ind = ...
print('ind = ', ind)

# Find the beginning of the first full symbol within the received samples.
# To do that, you should look for a phase transition of roughly pi between
# the inner products of two properly chosen consecutive chunks of received
# samples with the pa_sequence. If your code works properly, you should find
# that the first complete symbol starts at sample number 1744.

index_start_first_symbol = ...
print('index_start_first_symbol = ', index_start_first_symbol)


# Extract from the received samples the portion corresponding to full
# symbols and process it accordingly in order to generate the sufficient
# statistics about the transmitted data symbols. Plot the result. If your
# code works properly, you should obtain a rotated (and noisy) BPSK
# constellation.



# Knowing that the first transmitted symbol was a +1, estimate the phase
# introduced by the channel. If your code works properly, you should get a
# phase of about 2.07 radians.
phase_shift = ...
print('phase_shift = ', phase_shift)

# Correct for the phase rotation, take decisions in oder to estimate the
# transmitted data symbols and compute the symbol error rate (SER). If
# everything works correctly, you should get SER = 0.

SER = ...
print('SER = ', SER)
