Assembling ".h5" file

701 views
Skip to first unread message

fram...@gmail.com

unread,
Feb 27, 2016, 10:25:30 AM2/27/16
to Acoular-users
Dear Acoular developers and users,
We have the microphones array time data and we must know how to assemble a “.h5” file with such data to be read in the acoular software.
Our sample rate is 51200 Hz and we have 1995000 samples.
Can you help us to write/create the “.h5” file?
F.R.A., University of Sao Paulo

Ennes Sarradj

unread,
Mar 3, 2016, 9:55:36 AM3/3/16
to Acoular-users
Framaral,
I assume that you have some basic knowledge about the HDF5 (*.h5) format in general (if not, see https://www.hdfgroup.org/HDF5/).
The *.h5 files used by Acoular have a very simple structure: They contain one single
ARRAY object with the name 'time_data' and the dimensions (number of  samples) x (number of channels). The 'time_data' object must also have an attribute 'sample_freq' that gives the sample rate as floating point number. You may use the example files provided with Acoular and have a look at using HDFView (https://www.hdfgroup.org/products/java/hdfview/index.html).

In principle, you may assemble such file from your data using Python or MATLAB, C, Fortran or some other HDF5 supporting language.

Acoular itself also has some facilities do generate *.h5 files:
1. WriteH5 class
You may have a look at the (only few lines) source code in order to understand how the file is written.
2. classes of acoular.fileimport
These are specialized (and not well documented) classes to import data in several other file formats into *.h5. Again, the source code would help
3. acoular.nidaqimport (Windows only)
Does a measurement using NI hardware. First you have to define at least one NI Task (using NI MAX), then you can run this to start a GUI and from this the measurement and data storage in *.h5.
4. ResultExplorer.py (no longer in active development)
Is a graphical user interface you will find in the Python scripts directory which will provide also a GUI for importing and measuring data.

Hope this helps,
Ennes

fram...@gmail.com

unread,
Apr 16, 2016, 3:06:30 PM4/16/16
to Acoular-users
Dear Mr. Sarradj,

Thanks for your answer.

I'm trying to write a ".h5" file, via Matlab, to be read by the acoular package.
I have 62 vectors of microphone temporal signals acquired at 51200 [Hz] sample rate.

Here is the Matlab code that I'm using:

h5create('run.h5'/time_data',[numsamples numchannels]);
h5write('run.h5'/time_data',time_data);
h5writeatt('run.h5','/time_data','sample_freq',sample_freq);

I'm writing  the "sample_freq" attribute as a floating point number, however the acoular package says to me that such an attribute is an array: TraitError: The 'sample_freq' trait of a TimeSamples instance must be a float, but a value of array([ 51200.]) <type 'numpy.ndarray'> was specified.

Do you have any idea of what is happening?

Graciously,

Ennes Sarradj

unread,
Apr 18, 2016, 1:02:00 PM4/18/16
to Acoular-users
I am not very familiar with the MATLAB hdf5 interface, but obviously MATLAB writes an 1x1 array of float during the h5writeatt command instead of just a float as this is expected by acoular. The solution would be to find out how to make MATLAB writing just a float, instead of a 1x1 array of float. Though I did not try by myself, I have reports from other acoular users successfully using MATLAB to write the *.h5 file.

Hope this helps.

the.am...@gmail.com

unread,
May 9, 2017, 8:22:50 AM5/9/17
to Acoular-users
Hello dear Acoular user,

I am also using Acoular Framework and having the same error which you got before.
Did you find any solution to Import the files from matlab or import them directly from acoular?
Thank you in advance.

Regards

fram...@gmail.com

unread,
May 9, 2017, 8:30:09 AM5/9/17
to Acoular-users
Hello,

As for now, I did not find any solution to this issue.

the.am...@gmail.com

unread,
May 11, 2017, 3:12:20 AM5/11/17
to Acoular-users
Hello,

I think the solution would be to add [0] to the end of the 298th line of the source code (sources.py). It would be like this:
self.sample_freq = self.data.get_attr('sample_freq')[0]
It worked for me and I could write .hdf5 Format in Matlab and import it to acoular. Hope it will work for you as well.

Regards

qin151...@gmail.com

unread,
Apr 19, 2018, 11:39:06 PM4/19/18
to Acoular-users
Dear student of college,I have the similar question.I need to convert Matlab data to a .h5 file. The fileimport module was found on the acoular website, but the code in the module is not clear. It has not been translated successfully.

Simon Jekosch

unread,
Apr 20, 2018, 7:26:23 AM4/20/18
to Acoular-users
Hello,

you can convert your Matlab files to Acoular readable .H5 files in python. For files until matlab file version 7 use the scipy.io package, for matlab file version 7.3 the pytables package. A minimal example for both version is shown below:

#import
import tables
import numpy
from scipy.io import loadmat ,savemat
 
#insert working folder and data

folder='./Data/' #that contains the matlab data
filename='three_sources.h5'
N_channels = 64 #microphone channels
fs= 51200.0 #sample frequency


###################################
#matlab until 7.0 with scipy loadmat

matfile7 = loadmat(folder+'three_sourcesv7.mat')
tmp = matfile7['ans']
data_matlab7= numpy.zeros(tmp.shape, dtype='float32')
data_matlab7[:,:] = tmp 

savename = 'acoular_from_matlab_7_'+filename

#save_to acoular h5 format
acoularh5 = tables.open_file(folder+savename, mode = "w", title = filename)
acoularh5.create_earray('/','time_data', atom=None, title='', filters=None, expectedrows=100000, chunkshape=[256,64], \
                         byteorder=None, createparents=False, obj=data_matlab7)
acoularh5.set_node_attr('/time_data','sample_freq', fs)
acoularh5.close()

###################################
#matlab 7.3 is in hdf5
#can be importet with pytables

matfile73 = tables.open_file(folder+'three_sourcesv73.mat', mode = 'r')
tmp=matfile73.get_node("/ans")
read_signals = numpy.zeros(tmp.shape, dtype='float32')
read_signals[:,:] = tmp  
#matlab transposes eArrays
data_matlab73 = read_signals.T
savename = 'acoular_from_matlab_73_'+filename
#save_to acoular h5 format
acoularh5 = tables.open_file(folder+savename, mode = "w", title = filename)
acoularh5.create_earray('/','time_data', atom=None, title='', filters=None, expectedrows=100000, chunkshape=[256,64], \
                        byteorder=None, createparents=False, obj=data_matlab73)
acoularh5.set_node_attr('/time_data','sample_freq', fs)
acoularh5.close()

cheers,
Simon

Jim Aldon D'Souza

unread,
Nov 4, 2020, 6:18:16 PM11/4/20
to Acoular-users
Hi Ennes,

Thanks for your reply. Do you know if  acoular expects the input time_data sound pressure values to be in Pascal or RMS Pascal?

Gert Herold

unread,
Nov 5, 2020, 3:07:07 AM11/5/20
to Acoular-users
Input time data have to be sound pressures, i.e. positive and negative float values.
Reply all
Reply to author
Forward
0 new messages