From 1eeb46db05ce7734f77796cf0a3d99ccca21ca04 Mon Sep 17 00:00:00 2001 From: Chance Date: Thu, 26 Sep 2019 09:37:44 -0500 Subject: [PATCH] Working on a MIMO simulator --- phypy/mimo/__init__.py | 6 +++ phypy/mimo/channels.py | 0 phypy/mimo/mimo.py | 95 +++++++++++++++++++++++++++++++++++++++++ phypy/mimo/precoders.py | 0 requirements.txt | 4 +- 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 phypy/mimo/__init__.py create mode 100644 phypy/mimo/channels.py create mode 100644 phypy/mimo/mimo.py create mode 100644 phypy/mimo/precoders.py diff --git a/phypy/mimo/__init__.py b/phypy/mimo/__init__.py new file mode 100644 index 0000000..5cad29c --- /dev/null +++ b/phypy/mimo/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +"""MIMO Module for PhyPy""" + +__author__ = """Chance Tarver""" +__email__ = 'tarver.chance@gmail.com' diff --git a/phypy/mimo/channels.py b/phypy/mimo/channels.py new file mode 100644 index 0000000..e69de29 diff --git a/phypy/mimo/mimo.py b/phypy/mimo/mimo.py new file mode 100644 index 0000000..a99d47d --- /dev/null +++ b/phypy/mimo/mimo.py @@ -0,0 +1,95 @@ +import numpy as np +import simpy + + +class MimoTransmitter: + """ Class that represents an entire MIMO Transmitter Array. Includes channel and precoder.""" + + def __init__(self, + n_antennas: int = 64, + n_users: int = 4, + precoder: str = 'zero_forcing', + update_precoder_frequency: int = 7): + self.n_antennas = n_antennas + self.n_users = n_users + self.channel_matrix = None # Will store the channel matrix when we get it. + self.precoder = ZeroForcing(self.channel_matrix, update_precoder_frequency) + + def update_channel(self, channel): + """ The channel object exists in its own object. Periodically, our transmitter will get new CSI/channel. + This method updates the classes copy of the channel""" + + def transmit(self, symbols): + pass + + +class LinearPrecoder: + def __init__(self): + pass + + def precode(self, symbols): + out = np.dot(self.precoding_matrix, symbols) + return out + + def precode_update_process(self, env): + env.timeout( + 0.001 + ) # Small delay so that we always update based on a new channel + while True: + print(f'Current Symbol = {env.now}. Updating precoder') + self.create_precoder_matrix(self.precoding_matrix) + yield env.timeout(self.update_rate) + + +class ZeroForcing(LinearPrecoder): + def __init__(self, channel_matrix, update_rate): + self.precoding_matrix = None # Will be set by create_precoder_matrix method + self.create_precoder_matrix(channel_matrix) + self.update_rate = update_rate + + def create_precoder_matrix(self, channel_matrix): + self.precoding_matrix = channel_matrix + + +class MIMO_Channel: + def channel_update_process(self, env): + while True: + print(f'Current Symbol = {env.now}. Updating channel') + self.update_channel() + yield env.timeout(self.update_rate) + + +class MimoAwgn(MIMO_Channel): + def __init__(self, n_users: int = 8, n_antennas: int = 64, n_subcarriers=1200, update_rate: int = 7): + self.n_users = n_users + self.n_antennas = n_antennas + self.n_subcarriers = n_subcarriers + self.update_rate = update_rate + self.matrix = 1 + + def update_channel(self): + new_channel = 0.9*old_channel + guassian + pass + + +if __name__ == "__main__": + env = simpy.Environment() + update_channel_frequency = 1 # Every 2 symbols, make new MIMO channel + update_precoder_frequency = 7 + n_users = 4 + n_antennas = 64 + n_subcarriers = 1200 + n_symbols = 64 + + channel = MimoAwgn(n_users=n_users, n_antennas=n_antennas, n_subcarriers=n_subcarriers) + tx = MimoTransmitter(n_users=n_users, n_antennas=n_antennas, + update_precoder_frequency=update_precoder_frequency) + env.process(channel.channel_update_process(env)) + env.process(tx.precoder.precode_update_process(env)) + env.run(until=n_symbols) + + print(tx.n_antennas) + print(tx.n_users) + print(tx.precoder) + + diff --git a/phypy/mimo/precoders.py b/phypy/mimo/precoders.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index 283f5d5..19b9d6f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,6 @@ Sphinx==1.8.5 twine==1.14.0 Click==7.0 pytest==4.6.5 -pytest-runner==5.1 \ No newline at end of file +pytest-runner==5.1 +numpy +simpy