def coding(self, matrix): api = mathcadApi() c = self.channel_encoder(api.submatrix(matrix, 0, 3, 0, 0)) for j in range(1, int(np.floor(len(matrix) / self.k)) - 1): b = self.channel_encoder( api.submatrix(matrix, self.k * j, self.k * j + (self.k - 1), 0, 0)) c = api.stack(c, b) return c
def decoding(self, matrix, N): api = mathcadApi() c = self.channel_decoder(api.submatrix(matrix, 0, 6, 0, 0), N) for p in range(1, int(np.floor(len(matrix) / self.n)) - 1): a = self.channel_decoder( api.submatrix(matrix, p * self.n, (p + 1) * self.n - 1, 0, 0), N) c = api.stack(c, a) return c
def channel_decoder(self, T, N): api = mathcadApi() b = list() b.insert(0, T[0] ^ T[1] ^ T[3] ^ T[4]) b.insert(1, T[0] ^ T[2] ^ T[3] ^ T[5]) b.insert(2, T[1] ^ T[2] ^ T[3] ^ T[6]) if sum(b[:3]) != 0: for j in range(7): column = api.subcolumn(N, j) if sum(np.logical_xor(column, b)) == 0: T[j] ^= 1 return T
def getErrorChances(self, M, D, decoding=False, **kwargs): api = mathcadApi() P = list() for i in range(25): sigma = (i + 1) / 10 N = api.rnorm(len(M), 0, sigma) H = M + N R = self.detect(H) if decoding: F = self.decoding(R, kwargs['N']) P.insert(i, api.getErrorChance(D, F)) else: P.insert(i, api.getErrorChance(D, R)) return P
from matplotlib import pyplot as plt from components.DTS import digitalTransmission from components.encryption import SimpleDEncryptor from modules.utils import writeInFile, savePlot, createTimeLine, parseErrorChances from modules.api import mathcadApi from config import path import numpy as np import ast if __name__ == '__main__': api = mathcadApi() np.seterr(divide='ignore') # Генерируем массив D = api.rbinom(1000, 1, 0.5) # Создаём экземпляр класса dt = digitalTransmission(sigma=0.5, q=20, tau=0.1, matrix=D) # Создаём таймлайн модели для отрисовки на графике timeline = createTimeLine(0, len(D) * dt.tau - dt.Ts, dt.Ts) print("TIMELINE", timeline) """ Получаем массив отсчетов сигнала с выхода модулятора M, соответствующих модельному времени. При подаче на вход массива """ M = dt.BPSK(timeline, D) writeInFile(str(M), path + '\data\\bpsk.txt', 'Фазовая модуляция') savePlot(plt, 'p1.png',