<jupyter_start><jupyter_text>* Considerar retransmissão no modelo de consumo energético* Transmissão fase-quadratura* Desvanecimento por múltiplos percursos* Transmissão    * Transmissão de $X$ bits em $P$ pacotes, sem erro    * $X/P$ bits por pacote    * Energia para transmissão de um pacote é $E$ (uma unidade de energia)    * Repetir transmissão de todo o pacote um bit for recebido errado<jupyter_code>def add_noise(message, variance):
    n = np.size(message)
    stddev = np.sqrt(0.5 * variance)
    alpha = np.random.normal(0, stddev, n)
    codx = np.random.normal(alpha * (message.real - message.imag), stddev, n)
    cody = 1j * np.random.normal(alpha * (message.real + message.imag), stddev, n)
    return message + codx + cody
def demodulate(transmitted, alphabet):
    indices = np.abs(np.subtract.outer(alphabet, transmitted)).argmin(0)
    return np.asarray([alphabet[i] for i in indices])
# Quantidade total de bits a serem transmitidos (bits)
N = 10000

# Tamanho do pacote (bits/pacote)
Np = 100

# Símbolos 4-QAM
symbols = [1+1j, -1+1j, -1-1j, 1-1j]

# Mensagem para transmissão
message = np.random.choice(symbols, N)
assert_equal(demodulate(message, symbols), message)
%run ../wavelet.py
wavelet = Wavelet(m=2, g=64)
wavelet.mcw_from_coefficients('../mcw2_128.txt', Np)
alphabet = np.array([-wavelet.mg + 2 * k for k in range(wavelet.mg + 1)])
def qam_transmission(message, No, Np, P):
    """Performs an stream transmission using QAM scheme
    
    Parameters
    ----------
    message: stream to be transmitted
    Np: number of bits per package
    P: number of packages transmitted if no error occur
    No: system's variance
    
    Return
    ------
    Total of transmissions until every package has been delivered
    """
    assert np.size(message) % Np == 0, "message length should be a multiple of Np"
    k = 0
    cnt = 0
    while k < P:
        slice_of_message = message[k * Np: (k + 1) * Np]
        transmitted = add_noise(slice_of_message, No)
        demodulated = demodulate(transmitted, symbols)
        cnt += 1
        if np.array_equal(slice_of_message, demodulated):
            k += 1
    return cnt

def mcw_transmission(message, No, Np, P, wavelet):
    """Performs an stream transmission using QAM scheme
    
    Parameters
    ----------
    message: stream to be transmitted
    Np: number of bits per package
    P: number of packages transmitted if no error occur
    No: system's variance
    wavelet: Wavelet object initialized according to Np
    
    Return
    ------
    Total of transmissions until every package has been delivered
    """
    k = 0
    cnt = 0
    while k < P:
        slice_of_message = message[k * Np: (k + 1) * Np]
        encoding = wavelet.encode(slice_of_message.real) + 1j * wavelet.encode(slice_of_message.imag)
        transmitted = add_noise(encoding, No)
        demodulated = demodulate(transmitted.real, alphabet) + 1j * demodulate(transmitted.imag, alphabet)
        decoded = np.sign(wavelet.decode(demodulated.real)) + 1j * np.sign(wavelet.decode(demodulated.imag))
        cnt += 1
        assert_equal(np.size(slice_of_message), np.size(decoded))
        if np.array_equal(slice_of_message, decoded):
            k += 1
    return cnt<jupyter_output><empty_output><jupyter_text>Teste<jupyter_code># Quantidade de pacotes necessários na ausência de erro
P = N / Np

# Variância fixa (teste)
No = 0.1

print(f"No = {No}")
print(f"{P:.0f} pacotes com {Np} bits cada")
print("Energia consumida - QAM: %d * E" % qam_transmission(message, No, Np, P))
print("Energia consumida - MCW: %d * E" % mcw_transmission(message, No, Np, P, wavelet))<jupyter_output>No = 0.1
100 pacotes com 100 bits cada
Energia consumida - QAM: 1062 * E
Energia consumida - MCW: 101 * E<jupyter_text>Simulação com range de variâncias<jupyter_code>No = np.arange(0, 0.2, 0.01)
energy_qam = np.zeros(np.size(No))
energy_mcw = np.zeros(np.size(No))

for i, no in enumerate(No):
    energy_qam[i] = qam_transmission(message, no, Np, P)
    energy_mcw[i] = mcw_transmission(message, no, Np, P, wavelet)
import matplotlib.pyplot as plt
plt.style.use('seaborn-ticks')
%matplotlib notebook

plt.plot(No, energy_qam, '-x', label='4-QAM')
plt.plot(No, energy_mcw, 'r-x', label='MCW')
plt.legend()
plt.xlabel('$N_0$')
plt.ylabel('Unidades de energia')
plt.yscale('log')
plt.title('Consumo energético em função da variância. Canal com desvanecimento');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12072072072072072, 'fraction_numerical': 0.01599099099099099, 'mean_word_length': 3.513211382113821, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '552930', 'license': 'MIT', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1578, 'n_words': 437, 'path': 'notebooks/Estimacao_energia_QAM_vs_MCW.ipynb', 'repo_name': 'fmndantas/wavelet', 'size': '4440'}