Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
This sketch demonstrates how to log sensor data for later processing or analysis. The file can be written as either a binary file (using 32-bit floats) or as a formatted text file (again, only using floats). An optional header and footer can be added to text files, to make your file immediately ready to be opened in your favourite data analysis program.
Make sure you do not fill up your disk while logging. Current disk usage can be obtained by typing at the console:
$ df -h .
While the space occupied by a given file can be obtained with
$ ls -lh path/to/filename
To learn how to obtain more space on your filesystem, check out the wiki.
If you write text files, it is a good idea keep your lines short, as this usually makes it faster for other programs to process the file. The text file in this example breaks a line after each sample is logged (note the \n
at the end of the format string).
If you plan to write large amount of data, binary files are preferrable as they take less space on disk and are therefore less resource-consuming to write. They are also generally faster to read and parse than text files.
It is safe to call WriteFile::log() from the audio thread, as the data is added to a buffer which is then processed in the background and written to disk from a lower-priority non-realtime task.
The files generated by this program can be opened, e.g.: in GNU Octave or Matlab, with
``` filename = 'out.bin'; numChannels = 4; % num of channels in the binary file fid=fopen([filename],'r'); A = fread(fid, 'float'); % load in A the values logged to the binary file fclose(fid); A = vec2mat(A, numChannels); % transform the array A into a matrix with numChannels columns
run('out.m'); % this will create a variable myar with the data logged to the text file T = myvar(:,1); % the first column of the text file is timestamp plot(1:size(A, 1), A, T, myvar(:,2)); legend('analog0','analog1', 'analog2', 'analog3', 'analog4') ```