Post Go back to editing

Trouble Implementing MUSIC Algorithm

Thread Summary

The user is experiencing issues with precise DOA estimation using the MUSIC algorithm on the Phaser kit with two subarrays. The final answer suggests that phase mismatch between the two Rx channels of the PlutoSDR can be calibrated out, and directs the user to the pysdr.org documentation for further algorithm development. The key products involved are the AD9361 and CN0566, with the sample rate set to 30 MHz and center frequency at 2.2 GHz.
AI Generated Content
Category: Software
Product Number: CN0566
Software Version: Python 3.10.15

I have tried multiple ways to implement precise DOA estimation on The Phaser kit, one of them being the popular MUSIC algorithm. As the kit has two subarrays, it is possible to detect the precise DOA of only one object. The problem is that every time I run the script I get an estimated DOA around plus/minus 20 degrees even though the transmitter is placed at mechanical boresight or at some other angle. 

Below attached is the code that I have created. Please suggest me on what changes should i make to properly implement the algorithm.

Also I read about phase mismatch between the two Rx channels of the PlutoSDR, could that cause problems??

import adi
from adi import ad9361
from adi.cn0566 import CN0566
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
from numpy.fft import fft, fftfreq, fftshift
import ADAR_pyadi_functions as ADAR  
import helper_funcs
import SDR_functions as SDR
import aic
from doa_py import arrays, signals
from doa_py.algorithm import music
from doa_py.plot import plot_spatial_spectrum

#Key Parameters
sample_rate = 30e6
center_freq = 2.2e9
signal_freq = 100e4
  
rx_gain = 60
d = 0.056
c= 299792458




#%% Initial Setup
# Instantiate all the Devices
rpi_ip = "ip:phaser.local"  # IP address of the Raspberry Pi
sdr_ip = "ip:192.168.2.1"  # "192.168.2.1, or pluto.local"  # IP address of the Transceiver Block
my_sdr = adi.ad9361(uri=sdr_ip)
my_phaser = adi.CN0566(uri=rpi_ip)


# Initialize both ADAR1000s, set gains to max, and all phases to 0
my_phaser.configure(device_mode="rx")
my_phaser.load_gain_cal()
my_phaser.load_phase_cal()
for i in range(0, 8):
    my_phaser.set_chan_phase(i, 0)

gain_list = [127,127,127,127,127,127,127,127] 
for i in range(0, len(gain_list)):
    my_phaser.set_chan_gain(i, gain_list[i])

# Setup Raspberry Pi GPIO states
my_phaser._gpios.gpio_tx_sw = 0  # 0 = TX_OUT_2, 1 = TX_OUT_1
my_phaser._gpios.gpio_vctrl_1 = 1 # 1=Use onboard PLL/LO source  (0=disable PLL and VCO, and set switch to use external LO input)
my_phaser._gpios.gpio_vctrl_2 = 1 # 1=Send LO to transmit circuitry  (0=disable Tx path, and send LO to LO_OUT)

# Configure SDR Rx
my_sdr.sample_rate = int(sample_rate)
sample_rate = int(my_sdr.sample_rate)
my_sdr.rx_lo = int(center_freq)
my_sdr.rx_enabled_channels = [0, 1]  # enable Rx1 and Rx2
my_sdr.gain_control_mode_chan0 = "manual"  # manual or slow_attack
my_sdr.gain_control_mode_chan1 = "manual"  # manual or slow_attack
my_sdr.rx_hardwaregain_chan0 = int(rx_gain)  # must be between -3 and 70
my_sdr.rx_hardwaregain_chan1 = int(rx_gain)  # must be between -3 and 70
my_sdr.rx_buffer_size = 2**12
my_sdr.rx_rf_bandwidth = int(2e6)

# Setup Raspberry Pi GPIO states
my_phaser._gpios.gpio_tx_sw = 0  # 0 = TX_OUT_2, 1 = TX_OUT_1
my_phaser._gpios.gpio_vctrl_1 = 1 # 1=Use onboard PLL/LO source  (0=disable PLL and VCO, and set switch to use external LO input)
my_phaser._gpios.gpio_vctrl_2 = 1 # 1=Send LO to transmit circuitry  (0=disable Tx path, and send LO to LO_OUT)

# Configure SDR Tx
my_sdr.tx_lo = int(center_freq)
my_sdr.tx_enabled_channels = [0, 1]
my_sdr.tx_cyclic_buffer = True  # must set cyclic buffer to true for the tdd burst mode.
my_sdr.tx_hardwaregain_chan0 = -88  # must be between 0 and -88
my_sdr.tx_hardwaregain_chan1 = -0  # must be between 0 and -88

# Configure the ADF4159 Ramping PLL
output_freq = 12.725e9
my_phaser.frequency = int(output_freq / 4)  # Output frequency divided by 4
my_phaser.ramp_mode = "disabled"  # ramp_mode can be:  "disabled", "continuous_sawtooth", "continuous_triangular", "single_sawtooth_burst", "single_ramp_burst"
my_phaser.enable = 0  # 0 = PLL enable.  Write this last to update all the registers

# Intialize the ADAR1000 receive array
rx_array = adi.adar1000_array(
    uri=rpi_ip,
    chip_ids=["BEAM0", "BEAM1"],  # these are the ADAR1000s' labels in the device tree
    device_map=[[1], [2]],
    element_map=[[1, 2, 3, 4, 5, 6, 7, 8]],
    device_element_map={
        1: [8,7,5,6],  # i.e. channel2 of device1 (BEAM0), maps to element 8
        2: [4,3,1,2],
        },
    )
for device in rx_array.devices.values():
    ADAR.ADAR_init(device)  # resets the ADAR1000
    ADAR.ADAR_set_mode(device, "rx")  # ADAR1000s on Phaser are receive only, so mode is always "rx"


# Create a sinewave waveform
fs = int(my_sdr.sample_rate)
N = int(my_sdr.rx_buffer_size)
fc = int(signal_freq / (fs / N)) * (fs / N)
ts = 1 / float(fs)
t = np.arange(0, N * ts, ts)
i = np.cos(2 * np.pi * t * fc) * 2 ** 14
q = np.sin(2 * np.pi * t * fc) * 2 ** 14
iq = 1 * (i + 1j * q)

# Send data
my_phaser.sdr = my_sdr
my_phaser.sdr._ctx.set_timeout(0)
my_phaser.sdr.tx([iq * 0.5, iq])  

nSamples=my_phaser.sdr.rx_buffer_size



#%% MUSIC Algorithm

nSamples = my_phaser.sdr.rx_buffer_size
signal_mat=np.zeros((nSamples,2),dtype=complex)


data = my_phaser.sdr.rx()
signal_mat[:,0] = data[0]
signal_mat[:,1] = data[1]

plt.plot(data[0])
plt.plot(data[1])

print("\n\tsignal matrix\n")
print(signal_mat)


ula = arrays.UniformLinearArray(m=2, dd=0.015)
# Calculate the MUSIC spectrum
angle_grids = np.arange(-90, 90, 0.1)
spectrum = music(
    received_data=signal_mat.T,
    num_signal=1,
    array=ula,
    signal_fre=10.525e9,
    angle_grids=angle_grids,
    nSamples=nSamples,
    unit="deg",
)

# Plot the spatial spectrum
plot_spatial_spectrum(
    spectrum=spectrum,
    ground_truth=np.array([0,]),
    angle_grids=angle_grids,
    num_signal=1,
)

#%%Destroy

my_phaser.sdr.tx_destroy_buffer()
 

Thread Notes

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.