Hi,
I am developing an application that calculate the phase difference between a signal coming from the two RX channels of a limeSDR. So far, I have the code that calculates it and have fed a Sine using a splitter. The main problem here is that when I execute the program several times, the phase difference stops being the same between executions. Here is the code:
SoapySDR::Device *device(nullptr);
device = SoapySDR::Device::make();
//device->setMasterClockRate(8*sampleRate);
device->setBandwidth(SOAPY_SDR_RX, 0, 20e6);
device->setBandwidth(SOAPY_SDR_RX, 1, 20e6);
device->setSampleRate(SOAPY_SDR_RX, 0, sampleRate);
device->setSampleRate(SOAPY_SDR_RX, 1, sampleRate);
std::string format = SOAPY_SDR_CF32;//device->getNativeStreamFormat(SOAPY_SDR_RX, 0, fullScale);
const size_t elemSize = SoapySDR::formatToSize(format);
std::vector<size_t> channel(2);
channel[0] = 0;
channel[1] = 1;
auto rxStream = device->setupStream(SOAPY_SDR_RX, format, channel);
device->setFrequency(SOAPY_SDR_RX, 0, frequency);
device->setAntenna(SOAPY_SDR_RX, 0, "LNAL");
device->setGain(SOAPY_SDR_RX, 0, gain);
device->setFrequency(SOAPY_SDR_RX, 1, frequency);
device->setAntenna(SOAPY_SDR_RX, 1, "LNAL");
device->setGain(SOAPY_SDR_RX, 1, gain);
cout << "Rx 0 Frequency " << device->getFrequency(SOAPY_SDR_RX, 0)*1e-6 << " MHz" << endl;
cout << "Rx 1 Frequency " << device->getFrequency(SOAPY_SDR_RX, 1)*1e-6 << " MHz" << endl;
cout << "Rx 0 Antenna " << device->getAntenna(SOAPY_SDR_RX,0) << endl;
cout << "Rx 1 Antenna " << device->getAntenna(SOAPY_SDR_RX,1) << endl;
cout << "Rx 0 Sampling Rate " << device->getSampleRate(SOAPY_SDR_RX,0)*1e-6 << " Ms" << endl;
cout << "Rx 1 Sampling Rate " << device->getSampleRate(SOAPY_SDR_RX,1)*1e-6 << " Ms" << endl;
cout << "Rx 0 Bw " << device->getBandwidth(SOAPY_SDR_RX,0)*1e-6 << " MHz" << endl;
cout << "Rx 1 Bw " << device->getBandwidth(SOAPY_SDR_RX,1)*1e-6 << " MHz" << endl;
cout << "Clock rate: " << device->getMasterClockRate()*1e-6 << " MHz" << endl;
std::cout << "Starting stream loop, press Ctrl+C to exit..." << std::endl;
signal(SIGINT, sigIntHandler);
fftwf_plan p0;
fftwf_plan p1;
fftwf_complex *in0 = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * receiveWindow);
fftwf_complex *in1 = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * receiveWindow);
std::vector<void *> rxBuffs(2);
rxBuffs[0] = in0;
rxBuffs[1] = in1;
while(!loopDone){
//counter++;
int flags(0);
long long timeNs(0);
device->activateStream(rxStream);
int rxRet = device->readStream(rxStream, rxBuffs.data(), receiveWindow, flags, timeNs);
device->deactivateStream(rxStream);
cout << "Ret: " << rxRet << endl;
if (rxRet == SOAPY_SDR_TIMEOUT){
cout << "T" << endl;
continue;
}
if (rxRet == SOAPY_SDR_OVERFLOW)
{
cout << "O";
continue;
}
if (rxRet == SOAPY_SDR_UNDERFLOW)
{
cout << "U";
continue;
}
if (rxRet < 0)
{
std::cerr << "Unexpected stream error " << SoapySDR::errToStr(rxRet) << std::endl;
break;
}
if (rxRet == receiveWindow) {
vector<double> phaseDifference(receiveWindow, 0);
size_t histogramSpan = 720;
vector<double> histogram(histogramSpan, 0);
size_t i = 0;
double max = 0;
double maxPos = 0;
int angPos;
for (i = 0; i < receiveWindow; ++i) {
phaseDifference[i] =
std::arg(complex<float>(in0[i][0], in0[i][1]))
- std::arg(complex<float>(in1[i][0], in1[i][1]));
angPos = floor(phaseDifference[i] * 180.0 / M_PI) + histogramSpan*0.5;
histogram[angPos]++;
if (histogram[angPos] > max){
maxPos = angPos;
max = histogram[angPos];
}
}
cout << "-------------------------" << endl;
cout << "Max: " << max << endl;
cout << "MaxPos: " << maxPos << endl;
cout << "MaxPosAngle: " << maxPos - histogramSpan*0.5 << endl;
cout << "-------------------------" << endl;
sleep(1);
}
}
Is there anything else I should be doing? Reseting some configuration or something like that?
I will also try to make a similar program using the LimeSuite API and post it with the results.
Kind regards,
Aridane