Is there a way of sending and receiving signals for modulated signal's using python?

408 views Asked by At

Ive been trying to find ways of sending modulated signals on python which then later down the line do analyses on the data sent and received.

At the moment i just want to be able to send data using a modulation format such as PAM and then receive it

Any help would be appreciated thank you

2

There are 2 answers

0
Pascal Getreuer On BEST ANSWER

I haven't tried it, but there is a Komm Python library for analysis and simulation of communication systems. Komm includes an implementation of pulse-amplitude modulation komm.PAModulation, among other modulation schemes.

The komm.PAModulation class has a .modulate() method that takes data bits as input and modulates it to a transmit signal. And conversely, there is a .demodulate() method that takes a received signal the tries to demodulate data from it. It doesn't look like Komm comes with interfaces for radios or other modalities, so you'll need to figure out separately how to actually send and receive these signals.

0
TheWirelessClassroom On

There is a way of sending signals in simulations. E.g. if you want to transmit the bit combination 10 in a 4QAM system, you would have to start with a modulator, which maps this to a complex symbol: Lets say the mapping is 1+1j -> Now you would have to "transmit" this complex symbol over a channel which introduces distortion (e.g. additive white gaussian noise). At the receiver you now try to detect this symbol and map it back to the original 10 bit combination.

I would recommend you to program this from scratch to get a better understanding of the topic.

The code for a 4QAM Modulation could e.g. look like this:

import matplotlib.pyplot as plt
import numpy as np
import pylab as pyl

def modulate_4QAM(bits):
    b_temp = np.reshape(bits * 2 - 1, (-1, 2)) # reshape bits in [0,1] to [-1,1]
    x = 1 / np.sqrt(2) * (b_temp[:, 0] + 1j * b_temp[:, 1])
    return x

def detecting_4QAM(received_signal):
    # detecting (slicing) and de-mapping
    received_bits = np.zeros((len(received_signal), 2))
    received_bits[:, 0] = np.real(received_signal) > 0
    received_bits[:, 1] = np.imag(received_signal) > 0
    received_bits = np.reshape(received_bits, (-1,))
    return received_bits

if __name__ == '__main__':
    b = pyl.randint(0, 2, int(4)) # generate random bits
    x = modulate_4QAM(b) # map bits to complex symbols
    noisePower=10**(-5/20) #caltulcate the noise power for a given SNR value
    noise = (noisePower)*1/np.sqrt(2)*(pyl.randn(len(x))+1j*pyl.randn(len(x)))#generate noise
    y_AWGN =x+noise # add the noise to the signal
    b_received = detecting_4QAM(y_AWGN)

Note that scaling from a 4QAM to a 64QAM would result in an additional programming/typing overhead and toolboxes become very handy for that.

This is only a fraction of a coding example which simulates the BER over SNR of an AWGN with a 4QAM modulation from: https://github.com/TheWirelessClassroom/PythonExamples/tree/Modulation

P.S. I'm new to the forum and unsure if only the fraction or the full code is more helpful/wanted. I would be happy to get some feedback on that and change the post accordingly.