From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Dynamic Signal Acquisition

cancel
Showing results for 
Search instead for 
Did you mean: 

4472B lossless compression

Thanks gaving!

 

I also found that when the channels were set to lossless compression mode. The array return by ReadRaw has a size of 4 * x bytes with x the total samples recorded. However, the last 25% of the array was all zeros. So I guess this is what you mentioned earlier that the driver packed the raw data for us. So I save the first 75% of the array elements to data file and now I am trying to reconstruct from these raw data to the measured values. 

 

XR

0 Kudos
Message 11 of 12
(3,590 Views)

Here is an update. It seems that we can compress losslessly from 32-bit to 24-bit using 4472B in LabWindows/CVI. 

Assume that:

1, x channels, y sample/channel and so total z = x* y samples to record. 

 

What I did:

I. Save the lossless compression data:

1, Set the channels to lossless compression mode. 

2, Set a pointer to the array to store the data as raw_data = (unsigned char *) calloc (4*z, sizeof (unsigned char)). Note that the array size is 4*z bytes, which is the same as the non-compression mode array size. 

3, Use ReadRaw to read the accquired raw data. Checking the array (raw_data) returned by the function in CVI debug environment, one sees that the first 75% of the array is occupied by data (if the inputs are not zeros) and the last 25% are all zeros. If no compression mode is set, then the array of the same size are full of non-zero data.This seems to be consistent with gaving's comments, i.e., the driver packs the data if the lossless mode is set.However, the driver doesn't automatically drop the last 25% of the array.This also explains the array size in #2.

4, Use fwrite (3*z, sizeof (unsigned char), FILE * file_pointer) to write the first 75% of the raw_data to a file. 

 

II. Load the lossless compression data:

1, Since every datapoint is now composed of 3 bytes of raw data in the file. So read 3 bytes everytime and form it to a long number.

2, I am not sure why, but it seems that the most significant byte comes first, which seems to be contrast to the LittleEndian setting.  So I use

val = (val<<8) + *(raw_data+i*byte_per_number+j); to convert the 3 bytes of raw data to one data point. Here i is an index number from 0 to the total number of the data points I am expecting and j is the index number looping from 0 to 2 to load 3 bytes from the raw data file.

3, Scale the raw data with the calibration coefficients. More details can be found in this post: http://forums.ni.com/ni/board/message?board.id=100&thread.id=680&view=by_date_ascending&page=1

 

Again, thanks a lot to gaving and Todd. I do look forward to more explanations and comments to what was described above, especially II-2.

 

XR

0 Kudos
Message 12 of 12
(3,586 Views)