I am reading in a buffer of IQ data from a Software Defined Radio which I want to demodulate. The data I am receiving is a buffer of 8 bit unsigned int's. I need to convert this to buffer to type complex float for demodulation of the signal (I plan on using Liquid DSP Library). I am having difficulties in converting the buffer.
In GNURadio I have worked out my logic and am writing the output of my code to a binary file which I can then using as an input source for testing. So far the only thing that working is writing the uint8_t buffer to the file, other manipulation on the data breaks the logic.
Here is a snippet of the C++ code I have tried:
uint8_t buffer[buffersize];
uint8_t I;
uint8_t Q;
float Ifloat;
float Qfloat;
complex<float> complexsample;
ofstream myfile;
myfile.open("example.bin", ios::out | ios::app | ios::binary);
for (int x = 0; x < (buffersize/2); x++) {
memcpy(&I, buffer + (2 * x), 1);
memcpy(&Q, buffer + (1 + (2 * x)), 1);
//writing I and Q above to a binary file works
//myfile.write((char*) &I, sizeof(I));
//myfile.write((char*) &Q, sizeof(Q));
Ifloat = (float) I;
Qfloat = (float) Q;
//when I write Ifloat and Qfloat to a binary file then pass the
//file as an input source into the Add Const block things stop working
//myfile.write((char*) &IIfloat, sizeof(Ifloat));
//myfile.write((char*) &Qfloat, sizeof(Qfloat));
Ifloat -= 127.0;
Qfloat -= 127.0;
//what I would do to turn the turn the unsigned value into a signed value
//myfile.write((char*) &IIfloat, sizeof(Ifloat));
//myfile.write((char*) &Qfloat, sizeof(Qfloat));
complexsample.real(Ifloat);
complexsample.imag(Qfloat);
//what I would do to turn the I and Q floats into a single complex sample
//myfile.write((char*) &complexsample, sizeof(complexsample));
}