morgan-at-keysight / pyarbtools

Create waveforms and control Keysight signal generators in Python with PyArbTools.
Other
52 stars 14 forks source link

[Feature Request] Add custom OFDM modulation waveform type to wfmBuilder.py #4

Open morgan-at-keysight opened 4 years ago

morgan-at-keysight commented 4 years ago

OFDM waveforms are difficult to generate, and there's a significant barrier to entry given the complexity of the modulation type. Let's make it easier to build and analyze OFDM waveforms.

Multi-carrier OFDM is on the table here, but that might be a stretch goal.

Request is to add OFDM waveform type to wfmBuilder.py

emcware commented 1 year ago

I took a stab at this with some help from gpt4. import numpy as np import matplotlib.pyplot as plt

""" This example uses random QAM data and does not include channel coding or any of the intricacies involved in a real-world communication system. It is a simple simulation meant to illustrate the basic OFDM signal structure. """

def generate_ofdm_symbol(num_subcarriers, cp_length, data_symbols): """ :param num_subcarriers: :param cp_length: :param data_symbols: :return: """

Perform IFFT to move from frequency domain to time domain

ifft_result = np.fft.ifft(data_symbols, n=num_subcarriers)

# Add cyclic prefix by taking the last cp_length samples and prepending them to the symbol
cyclic_prefix = ifft_result[-cp_length:]
ofdm_symbol_with_cp = np.concatenate([cyclic_prefix, ifft_result])

return ofdm_symbol_with_cp

Parameters

num_subcarriers = 64 # Number of OFDM subcarriers cp_length = 16 # Length of the cyclic prefix num_symbols = 10 # Number of OFDM symbols to generate

Generate random QAM data symbols for illustration purposes

data_symbols = np.random.choice([1 + 1j, -1 + 1j, -1 - 1j, 1 - 1j], size=(num_symbols, num_subcarriers))

Generate the OFDM waveform

ofdm_waveform = np.array([])

for symbol in range(num_symbols): ofdm_symbol = generate_ofdm_symbol(num_subcarriers, cp_length, data_symbols[symbol]) ofdm_waveform = np.concatenate([ofdm_waveform, ofdm_symbol])

Plot the IQ constellation of the OFDM waveform

plt.figure(figsize=(5, 5)) plt.scatter(ofdm_waveform.real, ofdm_waveform.imag) plt.title('OFDM IQ Constellation') plt.xlabel('In-Phase') plt.ylabel('Quadrature') plt.grid(True) plt.show()