High-Speed Digitizers

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-5133, hws file to matlab

Solved!
Go to solution

Hi all,

 

I use USB-5133 to measure voltages from two channels simultaneously. For that I use the NI-SCOPE. The scope saves the measured data as hws-file. I need these files in Matlab but I cannot open them. What would be the simplest way to export and open this data in Matlab?

 

All help is greatly appreciated!

 

Joonas

0 Kudos
Message 1 of 12
(11,152 Views)

HWS is an HDF5 file with a set structure.  You can use Matlab's HDF5 functions to read it.  The structure is very similar to SCPI-DIF.  The top level node is wmf_groupn. This contains the writer information, file storage version numbers, and the four main nodes - id, axes, traces, and vectors.  The id contains information on the particular set of data.  traces, the top level object, contains a single trace for each waveform stored in the file.  Each trace is composed of two axes. axes can be implicit (determined by a formula) or explicit (determined by a vector).  Data is stored in this fashion to make the sharing of axes explicit and efficient.  For example, the X-axis data on a two channel scope is usually identical for both traces.  The file format reflects this.

 

You can browse an NI-HWS file using HDFView, the free HDF5 browser available from the HDF5 group.  This will allow you to find the different pieces and their relationships with each other.  NI-HWS uses a fair number of advanced HDF5 features, so be prepared.

 

If you have further questions, let us know.

Message 2 of 12
(11,151 Views)

Thank you for the valuable information! I downloaded HDFView and I was able to browse my .hws file. However, I was not able to open or view the file in Matlab (2007 and 2010). I used the command

 

fileinfo = hdf5info('example.hws') which returned an error:

 

Error in ==> hdf5info at 95
[info.Offset, info.GroupHierarchy, majnum, minnum, relnum] = ...

 

I'm pretty much only a beginner with Matlab so probably I've messed up with some basics. Anyway if you can see what's the problem here I'd appreciate. I attach the file I've used in the example. And the only information I need is the measured voltage vector with time information. 

0 Kudos
Message 3 of 12
(11,136 Views)
Solution
Accepted by joonasmikkola

I have never used Matlab, so will probably not be able to help you much.  However, be aware that NI-HWS uses HDF5 version 1.4.4, which was released about 2002 or 2003.  The current version of HDF5 is 1.8.5.  I seem to remember some forward compatibility issues with 1.4.4, but it has been a long time and I cannot remember details.  HDF5 saves the writer version in the file to allow forward compatibility, and the HDFView does not seem to have a problem with the file (I could plot the trace with no issues in the viewer).  You may need to set a compatibility option in your file read.  Check your documentation.

 

Data, stored as an array of I8s, is in one of two places (there is only one copy of the data, but it is linked from both locations):

wfm_group0 / vectors / vector0 / data

wfm_group0 / traces / trace0 / y-axis / data_vector / data

 

The scaling coefficients for the data are stored in

wfm_group0 / traces / trace0 / y-axis / scale_coef

This is an array of 64-bit floating point numbers with the offset first, followed by the scaling factor (a0, a1, ...).

 

 

Timing information in in attributes of x-axis:

absolute timestamp - wfm_group0 / traces / trace0 / x-axis / ref_time

first point relative to timestamp reference point - wfm_group0 / traces / trace0 / x-axis / start

acquisition period - wfm_group0 / traces / trace0 / x-axis / increment

 

Good luck.  My apologies for not being more help.

0 Kudos
Message 4 of 12
(11,129 Views)

Thank you so much! Now everything works fine and I'm able to import the data to Matlab.

0 Kudos
Message 5 of 12
(11,073 Views)

For those who may be reading this later, the data vectors can be I8, I16, I32, or DBL, depending on how the data was stored.  The NI-SCOPE Soft Front Panel will store in the smallest integer format which preserves the resolution of the measurement.  You can use HDFView to determine the datatype, since HDF5 files contain all type information.

0 Kudos
Message 6 of 12
(11,065 Views)

Dear Colleagues,

 

Sorry for answering to this entry 2 years and a half later than the last comment, but my doubt is alligned with what you have been talking about. (Of course, if you consider that I should open a new line in the forum, just tell me, please.)

 

I have followed all your key points to read some *.HWS files i capture with a PXI NI5124 (12 bits, 2 channels).

I'm already able to read the data in labview and in Matlab, BUT I found a problem with the scaling of the data i have stored:

 

I took the signals simultaneously (2 channels) from -1V to +1V, but all the data have been stored in INTEGER number like:

16 112 32 128 96 64 80 80 0 32 -48 16 64 48 48 0 16 48 80 16 48 48 16 -16 16 -48 -80 -48 -96 -96 -80 16 -64 -16 -16 48 64 64 144 176 160 128 160 176 160 128 96 32 -16 -64 -160 -128 -160 -160 -176 -176 -192 -96 -32 0 48 48 112 80 192 192 192 192 208 160 64 144 32 -160 16 -64 -128 -256 -176 -128 -192 -208 -144 -48 -128 -256 112 320 16

These are only few samples, as I took 1.000.000 Samples @ 50 MSamples / s per file. I had some values up to +32000 and down to -29000, aprox.

 

I was surprised as i should had values like 0.001, 0.002 -0.2, -0.00005, etc.

 

The point is that I have found the scaling coefficients that are applied for each channel:

CH0 a:-1,143859 and b:3,2599724

CH1 a:-1,427364 and b:1,6671666

 

But I don't know how to scale the values i have registered down to the real ones. And I haven't found how this scaling works on the HWS files.

 

Thank you very in advance. I wold appreciate any help or int...

Best regards,

 

0 Kudos
Message 7 of 12
(9,671 Views)

Since the 5124 is a 12 bit digitizer, the data is saved at 16 bit integers to save space (it is also compressed).  The scaling coefficients, as mentioned in my second post above, are for a simple polynomial scaling.  However, the numbers you have posted for the scaling coefficients do not make sense.  The first value (the offset) is reasonable.  The second value (linear scale) should be on the order of 10-4 or so to scale the 16-bit integers down to the range they should be.  Please attach your file so we can take a look.  You may have just missed the exponent.

 

As mentioned above, I am not a Matlab user, so can not offer direct advice.  However, I would be very surprised if Matlab does not offer a simple function to scale your arrays, given the intial array and the polynomial coefficients.

 

My apologies for the very late reply.  I have been out on vacation.

0 Kudos
Message 8 of 12
(9,640 Views)

Dear DFGray,

 

Thank you for your help!

The day before going on vacation I did realize that the data were saved in I16 as you just told. So I supposed that the only "problem" I had, to see the real values, was that I had to divide the values by 2^16 (actually by 2^15 because the range I was saving the data was from -1V to +1V ), and to forget these coefficients. I opened an issue with the NI support team and they haven't told me about these coefficients...

But now that you tell me about the exponent, I had a look again and wide opened the window where the were anotated and you are right. The complete values are:

0: -1.14386 E-4

1: 3.26 E-5

 

So, should I multiply by 1 / 2^15

or should i do the opperation: "Data * 3.26 E-5 +1.14386 E -4"

 

Thank you very much for your wisdom!

And ahave a happy new year!

 

Iñigo Adin

 

 

0 Kudos
Message 9 of 12
(9,634 Views)

 

So, should I multiply by 1 / 2^15

or should i do the operation: "Data * 3.26 E-5 - 1.14386 E -4"



Definitely the second.  Note the change to a minus on the offset.  That coefficient is negative.  Good luck!

 

The reason for the difference between 1/215 and 3.26x10-5 is that the 12 bit number of the digitizer gets shifted four bits upward when converted to a 16 bit number.

0 Kudos
Message 10 of 12
(9,631 Views)