Exporting Acoustic Data to Matlab

Andy Todd

Posted on 01.11.2023 22:19

Hi all - hope you are well.


We are trying to export some acoustic measurement data from Dewesoft into Matlab for further analysis.


We have had slight success using Dewesoft wav export and importing this to Matlab - however the measured values are then incorrect and are arbitrary, so it is not possible to accurately calculate fft etc.


We have also tryed exporting in Matlab format, but this also does not seem correct - see image attached.


  1. Dewesoft data:


2. As shown in Matlab following export from dewesoft in matlab format.



So basically we are looking for a method to get the raw data into Matlab so that FFT, CPB etc can be calculated with correct values.


Hope that makes sense!


Andy

Pika Kreča Šmid

Posted on 02.11.2023 14:21

Dear Andy,


thank you for reaching out to us.

I have done a couple tests with my own datafile and DewesoftX version 2023.5. I can confirm that the following Matlab export is not correct. I believe it is a scaling issue, that appears to have been fixed with the 2023.6 RC version of DewesoftX.

As previously stated, I took my own file and exported the data to MATLAB, first in 2023.5, then in 2023.6. The .5 version produces a result, similar to yours. The .6 version, however produces correct values. You could, therefore try downloading the RC for the newest DewesoftX version.


I believe you could also work with .txt files, and .csv files.

From MathWorks documentation on importing Spreadsheets;

''Spreadsheets, such as Microsoft® Excel® files, often contain a mix of numeric and text data as well as variable and row names. While the most common way to represent spreadsheet data in MATLAB® is by using a table, you can also represent spreadsheet data in MATLAB as timetables, matrices, or cell arrays.

Import data from spreadsheets either programmatically or interactively. Import programmatically using tailored importing functions, and further control how your data is imported using import options. Import interactively by using the Import Tool.''


On the image below is how I have exported my data from a .csv file, but I believe you could do the same for a plethora of other datafiles, such as .txt, or .xlsx.

My datafile was called Test_Tok1.csv


We use the readtable(data) command to read the data. We then use the disp() command to display the data, just to confirm that everything works as it should. We set the first (time) column as Time, and the second (values) as y. In the end we plot a graph with a plot() command. 

This should now give you correct values.


Here is the code I have used:

my_csv=readtable('data.csv');

disp(my_csv);

Time = my_csv{:,1};

y = my_csv{:,2};

plot(Time,y);


I will also include my .csv file and my .dxd file, just in case you'd like to test this on my data.


Best regards,

Pika


Attached files:
Andy Todd

Posted on 02.11.2023 16:17

Hi Pika, thanks for getting back to me :)


You are right, the RC version does now export correctly to Matlab:



The issue I have now is that I think there is a step missing - as when I try to convert this to an octave spectrum, Dewesoft obviously knows the scaling etc - whereas Matlab gives some different values:



I was wondering if there was another scaling factor which needs to be applied? I was thinking Matlab might be expecting values in dB rather than Pa?


Any thoughts welcome!


Andy

Pika Kreča Šmid

Posted on 03.11.2023 09:57

Hello Andy,


If I understand correctly, you are trying to recreate the graph from DewesoftX (on the right side in your image) in MATLAB (on the left in your image). Is this correct? 

I have used the a sound measurement, exported it to MATLAB, and created the following image. As you can see, in my case, everything works as expected. 



We might be dealing with two issues here. The first issue is related to time vs. blocks. 

When using Octave analysis, you are using either a Block History or Overall Calculation type. Usig Overall type means, that the program will make an average calculation over the entirety of the data, meaning, no matter at what time you are looking, the Octave graph will always look the same.

If we use block history, the octaves will be calculated periodically in specified time increments. This means that the graph will change over time. In case you are using this type of calculation, you will have to take great care in choosing the correct block you are working with, so that the block corresponds with the correct time.

In the image below, you can see the Calculation type I've used. As you can see, the used type was Block history, with update rate of 200ms, meaning that I get a new calculation every 200ms.



The other image is how the CPB data is displayed in matlab. In my case, as you can see, I am displaying DATA1_Accelerometer_CPB.

DATA1 means that we are observing the data for the first channel, Accelerometer_CPB means what part of the data we are observing.

Each column corresponds to the amplitude at one frequency. Each row represents a value calculation for a block.

Data1_X_Accelerometer_CPB contains the frequencies.



Since I was working with the first block of data (the beginning of a measurement), I have used the first row of data, as this is the first calculation block. If I were to try and display data from the middle of my measurement, I would have to calculate, which block this time corresponds to.


The other issue is related to the Y Axis (value) from Dewesoft X. As you can see, I am using the default Y axis type- Log.

This is also how the data will be calculated and stored. You can change this type, as you have (in your case to Sound dB), but this only means that you will be displaying the data differently in DewesoftX. This will not change the way the data is stored, meaning that regardless of how you set this, the data will be stored in rms, not in dB rms.

You can, however, still get these values from DewesoftX, but do note, that you cannot export this data to .mat format this way. What you can do is press the widget, in your case 2D graph, then press the edit button in the upper-right corner, go to copy to clipboard, Widget data. I will also attach a video, for further clarification.


To sort of sum up, please check if you are using the correct blocks of data when working with MATLAB, and note, that in order to work with the dB rms units, you need to do the proper conversion from rms to dB rms in Matlab. the Y Axis (Value) settings apply only for the widget and have no effect on the stored data.


Best regards,

Pika


Attached files:
Andy Todd

Posted on 03.11.2023 10:20

Hi Pika, thanks for the detailed reply - very helpful!


So in your example, I think you have exported the CPB analysis from Dewesoft into Matlab - correct?


What I'm trying to do is export the raw data from Dewesoft (Pa vs time) and have Matlab calculate the CPB (and hopefully some additional metrics also) - does that make sense?


Andy

Pika Kreča Šmid

Posted on 03.11.2023 13:51

Dear Andy,


I will try to go over what it is that we are trying to do, using the images you have sent to me. Please confirm that this is what you are doing;

In DewesoftX, you measure some acoustic measurement data. This data is being stored in Channel AI 1, and its unit is [Pa].

You then use Octave Analysis on this channel AI 1 to get CPB- you only need this as a reference.

You export Channel AI 1 as .mat file into MATLAB and use this data to calculate the CPB in MATLAB. During this time, you only use the DewesoftX channel, AI 1/CPB [dB rms] to see if MATLAB is working correctly.


First, please check if the time and AI 1 channel values are being exported to MATLAB correctly- check if the data for AI 1from DewesoftX matches the data AI 1 if you call these values in MATLAB. To make matters easier, you can export the AI 1 channel as .txt file and compare the numerical values.

If the data is being exported correctly, and if you are doing your analysis in the above mentioned way, then there isn't much we can do from Dewesoft side of things, as this would then become a MATLAB issue. I believe you are working with the poctave command in MATLAB. I have tried to use this command to test how MATLAB behaves, however, I am sadly not versed enough to get the command to work. I did take a look the MATLAB forums, but did not find much information regarding this. I do have two forums I'd like you to take a look at; how to plot bar overall 1/3 octave by Poctave() as show below(bar color red)? and poctave() return value for acoustics analysis.


If I understand correctly, both of these MATLAB users are working with A weighted sound level, so perhaps you could try using the Sound Level module in DewesoftX, and take a look at what inserting such a channel would give you.


Best regards,

Pika

Login to reply to this topic. If you don't have account yet, you can signup for free account .