Corrupted Samples between Specific Indices of Samples

Hello,
I am trying to demodulate a basic AM modulated signal with 30MHz sine wave as carrier and 1KHz sine wave as the message using LimeSDR USB and LimeSuite API. Everything seems to work as expected, however, one problem that keeps coming up on every test is that there occurs some sort of corruption between exactly 5000th and 15000th samples. Did any of your come across a similar problem? Can you tell me why this occurs? Below, you can see a plot of the sampled signal with corruption. The code that I have used is also given below.

corrupt

Thank you.

The code:
indent preformatted text by 4 spaces
#include “lime/LimeSuite.h”
#include
#include
#include
#include “gnuPlotPipe.h”
#include <Windows.h>

using namespace std;
lms_device_t* device = NULL;

int error()
{
if (device != NULL)
LMS_Close(device);
exit(-1);
}

BOOL WINAPI consoleHandler(DWORD signal) {

if (signal == CTRL_C_EVENT)
	exit(1);
return TRUE;

}

int main(int argc, char** argv)
{
if (!SetConsoleCtrlHandler(consoleHandler, TRUE))
return 1;
int n;
lms_info_str_t list[8];
if ((n = LMS_GetDeviceList(list)) < 0)
error();
cout << "Devices found: " << n << endl;
if (n < 1)
return -1;

if (LMS_Open(&device, list[0], NULL))
	error();
if (LMS_Init(device) != 0)
	error();
int channel = 1;
cout << "Enable Channel: " << channel << endl;
if (LMS_EnableChannel(device, LMS_CH_RX, channel, true) != 0)
	error();
long c_freq = 30e6;
cout << "Center Freq: " << c_freq << endl;
if (LMS_SetLOFrequency(device, LMS_CH_RX, channel, c_freq) != 0)
	error();
long s_rate = 16e6;
cout << "Sample Rate: " << s_rate << endl;
if (LMS_SetSampleRate(device, s_rate, 0) != 0)
	error();

lms_range_t range;
if (LMS_GetLPFBWRange(device, LMS_CH_RX, &range) != 0)
	error();
if (LMS_SetLPFBW(device, LMS_CH_RX, channel, 1.4e6) != 0)
	error();
if (LMS_SetGFIRLPF(device, LMS_CH_RX, channel, 1, 10e3) != 0)
	error();
/*if (LMS_SetClockFreq(device, LMS_CLOCK_EXTREF, 10e6) != 0)
	error();*/

float_type freq;
LMS_GetClockFreq(device, LMS_CLOCK_REF, &freq);
cout << "FREEEEEEEEEEEEEEEEEEEEEEEEEEEEEQ: " << freq;
lms_stream_t streamId; //stream structure
streamId.channel = channel; //channel number
streamId.fifoSize = 2048 * 2048; //fifo size in samples
streamId.throughputVsLatency = 1.0; //optimize for max throughput
streamId.isTx = false; //RX channel
streamId.dataFmt = lms_stream_t::LMS_FMT_I12; //12-bit integers
if (LMS_SetupStream(device, &streamId) != 0)
	error();

//Initialize data buffers
const int sampleCnt = 100000;//5000; //complex samples per buffer
int16_t *buffer = new int16_t[sampleCnt * 2]; //buffer to hold complex values (2*samples))
LMS_StartStream(&streamId);

GNUPlotPipe gp;
for (int loop = 0; loop < 1; loop++)
{
	gp.write("set size square\n set xrange[0:100000]\n set yrange[-400:400]\n");
	int samplesRead = LMS_RecvStream(&streamId, buffer, sampleCnt, NULL, 1000);
	gp.write("plot '-' with points\n");
	for (int j = 0; j < samplesRead; ++j)
		gp.writef("%i %i\n", j, buffer[2 * j]);
	gp.write("e\n");
ofstream myfile;
myfile.open("C:\\Users\\ahmet\\Desktop\\example.txt");

for (int i = 0; i < samplesRead; i++)
{
	myfile << buffer[2*i]<<"\n";
}
myfile.close();
}

gp.flush();
//auto t1 = chrono::high_resolution_clock::now();
//while (chrono::high_resolution_clock::now() - t1 < chrono::seconds(5)) //run for 5 seconds
//{
//	//Receive samples
//	int samplesRead = LMS_RecvStream(&streamId, buffer, sampleCnt, NULL, 1000);
//	//I and Q samples are interleaved in buffer: IQIQIQ...
//	printf("Received %d samples\n", samplesRead);
//	/*
//		INSERT CODE FOR PROCESSING RECEIVED SAMPLES
//	*/
//	gp.write("plot '-' with points\n");
//	for (int j = 0; j < samplesRead; ++j)
//		gp.writef("%i %i\n", (j - samplesRead / 2), buffer[2 * j]);
//	gp.write("e\n");
//	gp.flush();
//}
//Stop streaming
LMS_StopStream(&streamId); //stream is stopped but can be started again with LMS_StartStream()
LMS_DestroyStream(device, &streamId); //stream is deallocated and can no longer be used

//Close device
LMS_Close(device);

return 0;

}

I am also having the same problem. Can anyone help, please?

I solved the issue, I just added a Sleep(1e6) function before receiving the stream and the data was not corrupted anymore.

1 Like