Open morgan-at-keysight opened 4 years 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: """
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
num_subcarriers = 64 # Number of OFDM subcarriers cp_length = 16 # Length of the cyclic prefix num_symbols = 10 # Number of OFDM symbols to generate
data_symbols = np.random.choice([1 + 1j, -1 + 1j, -1 - 1j, 1 - 1j], size=(num_symbols, num_subcarriers))
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])
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()
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