sofacoustics / SOFAtoolbox

SOFA Toolbox (API for Matlab, Octave)
http://sofaconventions.org
European Union Public License 1.2
116 stars 31 forks source link

How to fix properly dimensions of data #81

Open ReiNagahashi opened 9 months ago

ReiNagahashi commented 9 months ago

I am trying to convert 10 impulse responses into a single SOFA format data. I stored the data of the impulse responses in the field named hrtfData.Data.IR with dimensions MNR (where M is the number of measurements, N is the length of each impulse response, and R is the number of microphones).

When I executed SOFASave, I encountered the following error. Upon inspecting the data in hrtfData.API.Dimensions.Data.IR, it appeared to be cell-type data with the string 'mRn'. Even after updating it to hrtfData.API.Dimensions.Data.IR {1} = 'MNR' to match the dimensions of MNR, the error persists. Can you please provide guidance on the correct method for verifying and correcting the dimensions?

CODE:

M = 10;
N = 4800;
R = 2;

hrir_matrix = zeros(M, N, R);
%...Manipulation of inserting impulse response data into hrir_matrix for hrtfData.Data.IR...

sourcePosition = zeros(M, 3); # ex: [azimuth(deg), elavation(deg), radius(m)]
%...Manipulation of sourcePosition for hrtfData.SourcePosition...

% Create SOFA structure
hrtfData = SOFAgetConventions('SimpleFreeFieldHRIR');
%Configuration for hrtfData
hrtfData.API.M = M;
hrtfData.API.N = N;
% hrtfData.API.Dimensions.Data.IR{1} = 'MRN';

hrtfData.Data.SamplingRate = 48000;
hrtfData.Data.IR = hrir_matrix;
hrtfData.ListenerPosition = [0, 0, 0];  % 
hrtfData.SourcePosition = sourcePosition;
hrtfData.GLOBAL_History = 'converted by Rei';
% Save SOFAfile
SOFAsave('converted_measured_hrirs.sofa', hrtfData);

Error Message: 
Error: SOFAupdateDimensions (line 125)
Data.IR: dimension could not be matched.

Error: SOFAsave (line 60)
Obj=SOFAupdateDimensions(Obj);

Error: main (line 168)
SOFAsave('converted_measured_hrirs.sofa', hrtfData);