Jump to content
Fourth of July -- Digilent US offices closed ×
  • 0

Analog Discovery 2 - OFDM application


Ergest

Question

Hi,

I'm using an Analog Discovery 2 board with Python to transmit and record signals for an OFDM system. However, the output signal, when checked with a spectrum analyzer, shows peaks instead of a flat frequency response. I've tried using the AnalogOut_Custom.py script but it's not working as expected.

Can anyone suggest how to get a better frequency response with this setup, or any similar project that can show me the path? Also, how does the 'cSamples' variable affect the OFDM symbol samples?

Edit: This is what the spectrum analyzer shows: image.thumb.png.9a40c15723858943ee983ff5513c5a52.png

It is completely off, since I am using a center frequency of 5 kHz and a bandwidth of 3 kHz, 1024 subcarriers.

Thanks for any help!

Edited by Ergest
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

What are the limitations of implementing this in Python, and are there any exemplary guides for accomplishing this in the Waveform application? Should I script the generation of OFDM symbols or simply import them from a .csv file? Solely reading the file appears insufficient.

The OFDM consists of more than 62k samples. It's uncertain whether the buffer can manage this volume, but surprisingly, when I examine the time domain of the generated signal, it seems to encompass the entire signal, although the frequency spectrum is incorrect.

Link to comment
Share on other sites

  • 0

Hi @Ergest

The WF app uses the same API but I was referring that it is easier to control the device with the app, adjust parameters...

In the first (default) configuration of AD2 the AWG has 4Ki and in the 3rd 16Ki samples of device buffer allocated.

For lower sample rates (<1MHz) you can also use the Play/streaming mode for 'unlimited' length. See Play in WF app/Wavegen and example Python scripts: AnalogOut_Play.py AnalogOutIn_PlayRecord.py AnalogOutIn_PlayRecordStereo.py AnalogOutIn_RecordPlay.py

 

image.png

Link to comment
Share on other sites

  • 0

Hi @attila

Thank you for all your help in this matter. 

I use the following scriot to generate white Gaussian noise and bandpass it from 3k-5kHz:

 

from scipy.signal import butter, filtfilt
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sg
# Define the sample rate and the number of samples
fs = 100e3 
num_samples = 4096  # Number of samples

def bandpass_filter(signal, lowcut, highcut, f, order=5):
    nyq = 0.5 * f
    low = lowcut / nyq
    high = highcut / nyq
    b, a = butter(order, [low, high], btype='band')
    y = filtfilt(b, a, signal)
    return y

# Generate white noise
np.random.seed(0)
white_noise = np.random.normal(1, 2, num_samples)

# Define the bandwidth of the signal (1 kHz)
lower_cutoff = 3000  # Hz
upper_cutoff = 8000  # Hz

# Apply bandpass filter
band_limited_signal_adjusted = bandpass_filter(white_noise, lower_cutoff, upper_cutoff, fs)

plt.figure(figsize=(10, 4))
plt.plot(band_limited_signal_adjusted)
plt.title('Adjusted Band-limited Signal')
plt.xlabel('Time (seconds)')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()


plt.figure()
f, P = sg.welch(band_limited_signal_adjusted, fs)
plt.plot(f / 1e3, 10 * np.log10(P))
plt.xlabel('Frequency [kHz]')
plt.ylabel('PSD [dBm/Hz]')

# Frequency shift
fc = 50e3  # 50 kHz
# Time array
t = np.arange(num_samples) / fs

# Complex exponential for frequency shifting
complex_exponential = np.exp(1j * 2 * np.pi * fc * t)

# Shift the signal
pass_band_band_limited_signal = np.real(band_limited_signal_adjusted * complex_exponential)

plt.figure()
f, P = sg.welch(pass_band_band_limited_signal, fs)
plt.plot(f / 1e3, 10 * np.log10(P))
plt.xlabel('Frequency [kHz]')
plt.ylabel('PSD [dBm/Hz]')


image.png.0346bede03ad75d5769acef42d3b7f0b.png
image.png.12d1b40aeb5480291117a6a980c2ea4a.png

image.png.cfc80598fb0ff429e9436c662e68f10c.png

 

Then I followed the examples from AnalogOut_Play.py / AnalogOutIn_PlayRecord.py to write the following code:
 

from ctypes import *
import time
from dwfconstants import *
import sys

if sys.platform.startswith("win"):
    dwf = cdll.dwf
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
    
else:
    dwf = cdll.LoadLibrary("libdwf.so")

cSamples = len(pass_band_band_limited_signal)

hdwf = c_int()

# Convert the numpy array to ctypes array
rgdSamples = (c_double * cSamples)(*pass_band_band_limited_signal)

channel = c_int(0)

version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print("DWF Version: "+str(version.value))

# prevent temperature drift
dwf.FDwfParamSet(DwfParamOnClose, c_int(0)) # 0 = run, 1 = stop, 2 = shutdown

#open device
print("Opening first device...")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))


if hdwf.value == hdwfNone.value:
    print("failed to open device")


# 0 = the device will be configured only when calling FDwf###Configure
dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0))

dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_int(1))

dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, 0, funcCustom) 
dwf.FDwfAnalogOutNodeDataSet(hdwf, channel, 0, rgdSamples, c_int(cSamples))
#dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, 0, c_double(fs))
dwf.FDwfAnalogOutFrequencySet(hdwf, channel, c_double(fs)) 
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, 0, c_double(4))
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, 0, c_double(0))
dwf.FDwfAnalogOutRepeatSet(hdwf, channel, c_int(10000000)) # repeat 

dwf.FDwfAnalogOutConfigure(hdwf, channel, c_int(1))
dwf.FDwfAnalogOutReset(hdwf, channel)
dwf.FDwfDeviceClose(hdwf)


I have connected the BNC cable from AD2 to my picoscope and here is what I get in the spectrum analyzer.
image.thumb.png.d9c28f36d7df2b672c291e38b0633191.png



I also saved the 4096 samples in a file and upload to the waveform app, but it didn't solve anything. However when I generate a sweep from the Waveform app, I see the expected frequency spectrum.

Best, 
Ergest

 

image.png

Edited by Ergest
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...