PDA

View Full Version : Saving two data sets to the same file



amirlevi
31st August 2016, 06:24
Hello,
I'm working on an open source code for the Intan RDH2000 interface software.
I have two types of signals data - amplifier and auxiliary.
The amplifier is saved in the qint16 format and the auxiliary in the uqint16 format.
Moreover, the amplifier data is sampled every at each time step while the auxiliary data is sampled only at each 4th time step.
I'm trying (and so far failing) to merge these two signals type so they will both be on the same file with the same qint16 format.
About the time step, I don't mind to duplicate the auxiliary data so it will be identical for each 4 consecutive time steps.

Here is the function I'm working on, I'm new to QT and a little rusty in C++ so I would appreciate any suggestion you might have:


// Save amplifier data
bufferIndex = 0;
for (t = 0; t < SAMPLES_PER_DATA_BLOCK; ++t) {
for (i = 0; i < saveListAmplifier.size(); ++i) {
tempQint16 = (qint16)
(dataQueue.front().amplifierData[saveListAmplifier.at(i)->boardStream][saveListAmplifier.at(i)->chipChannel][t] - 32768);
dataStreamBuffer[bufferIndex++] = tempQint16 & 0x00ff; // Save qint16 in little-endian format (LSByte first)
dataStreamBuffer[bufferIndex++] = (tempQint16 & 0xff00) >> 8; // (MSByte last)
}
}
if (bufferIndex > 0) {
amplifierStream->writeRawData(dataStreamBuffer, bufferIndex); // Stream out all data at once to speed writing
numWordsWritten += saveListAmplifier.size() * SAMPLES_PER_DATA_BLOCK;
}

// Save auxiliary input data
bufferIndex = 0;
for (t = 0; t < SAMPLES_PER_DATA_BLOCK; ++t) {
tAux = 4 * qFloor((double) t / 4.0);
for (i = 0; i < saveListAuxInput.size(); ++i) {
tempQuint16 = (quint16)
dataQueue.front().auxiliaryData[saveListAuxInput.at(i)->boardStream][1][tAux + saveListAuxInput.at(i)->chipChannel + 1];
dataStreamBuffer[bufferIndex++] = tempQuint16 & 0x00ff; // Save quint16 in little-endian format (LSByte first)
dataStreamBuffer[bufferIndex++] = (tempQuint16 & 0xff00) >> 8; // (MSByte last)
}
}
if (bufferIndex > 0) {
auxInputStream->writeRawData(dataStreamBuffer, bufferIndex); // Stream out all data at once to speed writing
numWordsWritten += saveListAuxInput.size() * SAMPLES_PER_DATA_BLOCK;
}


With thanks,
Amir

anda_skoa
31st August 2016, 09:30
When you say you are failing, what is happening and what are you expecting happen instead?

Cheers,
_

amirlevi
31st August 2016, 10:01
I want the resulting file to be in the format of:
Amp1(t1) Amp2(t1) Amp3(t1).... Amp32(t1) Aux1(t1) Aux2(t1) ... Aux8(t1) Amp1(t2) Amp2(t2) .... Amp32(t2) Aux1(t2) Aux2(t2) ... Aux8(t2) and so on.
So far I'm not sure What I'm getting but it's not that.
I want to use the the "information preserving" option (uint16 to int16): translate (shift) to the -2^15 to 2^15-1 range which changes the values but preserve the data.

Best wishes,
Amir

anda_skoa
31st August 2016, 12:08
if you want this to be grouped by time, then you need to put the amp loop and the aux loop into the same time loop.

Currently you are iterating over your time range, then first write all amp values, then repeat the whole thing for aux.

I.e. you get

Amp1(t1), Amp2(t1), ..., Amp32(tMax), Aux1(t1), Aux2(t1), ..., Aux8(tMax)

Cheers,
_