Main Content

SimpleFreeFieldHRTF

SimpleFreeFieldHRTF SOFA convention

Since R2023b

    Description

    The SimpleFreeFieldHRTF object stores SOFA data following the SimpleFreeFieldHRTF convention. This convention describes a spatially discrete free-field head-related transfer function (HRTF) measurement for a single subject (a single human listener or a mannequin head device). The measurements are made in the free field with a single excitation source assuming an omnidirectional loudspeaker. There are two receivers representing the ears of the subject. The measured HRTFs are represented as complex frequency-domain transfer functions (TF).

    Use sofaread and sofawrite to read and write SOFA files with this convention.

    Creation

    Create a SimpleFreeFieldHRTF object using sofaconvention.

    s = sofaconvention("SimpleFreeFieldHRTF");

    Properties

    expand all

    Data

    Measurements in frequency response form, specified as a complex M-by-R-by-N array, where M is the number of measurements, R is the number of receivers, and N is the frequency response length. The number of receivers is typically equal to 2 in this convention.

    Frequency vector, in hertz, corresponding to the frequency response, specified as a vector.

    This property is read-only.

    Type of data in the file, returned as a string.

    Listener

    Listener position in Cartesian or spherical coordinates, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements.

    For more information, see Spatial Data Representations.

    Listener position type, specified as "cartesian" or "spherical".

    This property is read-only.

    Listener position units, returned as "meter" if ListenerPositionType is "cartesian" or "degree, degree, meter" if ListenerPositionType is "spherical".

    Listener view direction, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements. This property defines the direction of the positive x-axis of the local listener coordinate system.

    Listener view type, specified as "cartesian" or "spherical".

    This property is read-only.

    Listener view units, returned as "meter" if ListenerViewType is "cartesian" or "degree, degree, meter" if ListenerViewType is "spherical".

    Listener up direction, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements. This property defines the direction of the positive z-axis of the local listener coordinate system.

    Listener short name, specified as a string. This property defines the ID of the subject from the database.

    Receiver

    Receiver positions in Cartesian or spherical coordinates, specified as a 2-by-3 matrix or 2-by-3-by-M array, where M is the number of measurements and 2 represents the number of receivers. The default value assumes the head has a radius of 0.09 meters.

    For more information, see Spatial Data Representations.

    Receiver position type, specified as "cartesian" or "spherical".

    This property is read-only.

    Receiver position units, returned as "meter" if ReceiverPositionType is "cartesian" or "degree, degree, meter" if ReceiverPositionType is "spherical".

    Source

    Source position in Cartesian or spherical coordinates, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements.

    For more information, see Spatial Data Representations.

    Source position type, specified as "cartesian" or "spherical".

    This property is read-only.

    Receiver position units, returned as "meter" if SourcePositionType is "cartesian" or "degree, degree, meter" if SourcePositionType is "spherical".

    Source view direction, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements. This property defines the direction of the positive x-axis of the local source coordinate system.

    Source view type, specified as "cartesian" or "spherical".

    This property is read-only.

    Source view units, returned as "meter" if SourceViewType is "cartesian" or "degree, degree, meter" if SourceViewType is "spherical".

    Source up direction, specified as a 1-by-3 or M-by-3 matrix, where M is the number of measurements. This property defines the direction of the positive z-axis of the local source coordinate system.

    Emitter

    Emitter position in Cartesian or spherical coordinates, specified as a 1-by-3 matrix or 1-by-3-by-M array, where M is the number of measurements and 1 represents the number of emitters.

    For more information, see Spatial Data Representations.

    Emitter position type, specified as "cartesian" or "spherical".

    This property is read-only.

    Emitter position units, returned as "meter" if EmitterPositionType is "cartesian" or "degree, degree, meter" if EmitterPositionType is "spherical".

    Metadata

    This property is read-only.

    Name of the SOFA convention, returned as a string.

    Name of the database that this data belongs to, specified as a string.

    This property is read-only.

    Version of the SOFA AES69 specifications, returned as a string of the format "x.y" where x is the version major and y is the version minor.

    This property is read-only.

    Name of the API that created or edited the SOFA file, returned as a string.

    This property is read-only.

    Version of the API that created or edited the SOFA file, returned as a string of the format "x.y" or "x.y.z" where x is the version major and y and z are the version minors.

    This property is read-only.

    Version of the SOFA AES69 convention set, returned as a string of the format "x.y" where x is the version major and y is the version minor.

    Title containing a succinct description of the file contents, specified as a string.

    Contact information of the author (for example, an email address), specified as a string.

    Name of the organization of the author, specified as a string.

    Legal license under which the data is provided, specified as a string.

    Name of the application that created or edited the file, specified as a string.

    Version of the application that created or edited the file, specified as a string.

    Comment that can contain miscellaneous information about the data or methods used to produce the data, specified as a string.

    History defining the audio trail for modifications to the original data, specified as a string.

    Published or web-based references that describe the data or the methods used to produce the data, specified as a string.

    Origin, specified as a string representing the method used for creating the original data. In the case of model-generated data, the origin should name the model and its version. In the case of observed or measured data, the origin should characterize the data and, where possible, name the measurement method.

    This property is read-only.

    Date and time of the creation of the file, returned as a string in ISO 8601 format "YYYY-MM-DD hh:mm:ss". This property is set when a new file is created.

    This property is read-only.

    Date and time of the last file modification, returned as a string in ISO 8601 format "YYYY-MM-DD hh:mm:ss". This property is updated when a file is saved.

    Object Functions

    writeWrite SOFA file
    validateValidate SOFA data
    interpolateHRTF3-D head-related transfer function (HRTF) interpolation
    findMeasurementsFind measurements in specified plane
    plotGeometryPlot measurements geometry
    freqzHRTF frequency response
    spectrumHRTF power spectrum
    interauralLevelDifferenceInteraural level difference
    directivityFrequency directivity

    Examples

    collapse all

    Create a SOFA template object following the SimpleFreeFieldHRTF convention to store measurement data as complex frequency responses.

    s = sofaconvention("SimpleFreeFieldHRTF");

    Load HRTF data containing impulse response measurements. Initialize the FrequencyResponse property to store 100 measurements in 512-point frequency responses.

    load 'ReferenceHRTF.mat' hrtfData sourcePosition sampleRate
    M = 100;
    N = 512;
    R = 2; % 2 ears
    
    s.FrequencyResponse = complex(zeros(M,R,N));

    For 100 of the measurements from the HRTF data, use freqz to get the complex frequency responses from the FIR filters and store them in the SOFA object.

    for i = 1:M
        ear1FIR = squeeze(hrtfData(:,i,1));
        ear2FIR = squeeze(hrtfData(:,i,2));
        
        [h1,f] = freqz(ear1FIR,1,N,sampleRate);
        s.FrequencyResponse(i,1,:) = h1;
        h2 = freqz(ear2FIR,1,N,sampleRate);
        s.FrequencyResponse(i,2,:) = h2;
    end
    
    s.FrequencyVector = f;

    Set the SourcePosition property to store the positional data, in spherical coordinates, corresponding to the selected measurements.

    s.SourcePositionType = "spherical";
    s.SourcePosition = sourcePosition(1:M,1:3);

    Write the data to a SOFA file.

    sofawrite("freqResponseData.sofa",s);

    Read in a SOFA file that follows the SimpleFreeFieldHRTF convention and contains measurements in frequency response form.

    s = sofaread("freqResponseData.sofa");

    Select the complex frequency response corresponding to the tenth measurement and the right ear.

    measurementIdx = 10;
    ear = 2;
    
    freqResponse = squeeze(s.FrequencyResponse(measurementIdx,ear,:));

    Plot the magnitude response in decibels.

    plot(s.FrequencyVector,20*log10(abs(freqResponse)))
    xlabel("Frequency (Hz)")
    ylabel("Magnitude (dB)")

    Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type line.

    Read in a SOFA file containing HRTF measurements.

    s = sofaread("exampleSimpleFreeFieldHRTF.sofa");

    Call plotGeometry to visualize the 3-D locations of the receiver and moving source from the measurements.

    figure
    plotGeometry(s)

    Figure contains an axes object. The axes object with xlabel X (meters), ylabel Y (meters) contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Source position, Receiver position.

    Use findMeasurements to get the indices of measurements in the median plane. Plot the 3-D geometry of the specified measurements.

    idx = findMeasurements(s,Plane="median");
    figure
    plotGeometry(s,MeasurementIndex=idx);

    Figure contains an axes object. The axes object with xlabel X (meters), ylabel Y (meters) contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Source position, Receiver position.

    Use freqz to compute and visualize the frequency response of the first measurement for the first receiver.

    figure
    freqz(s)

    Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type line. This object represents Measurement 1. Receiver 1.

    Use spectrum to compute and visualize the power spectrum of the HRTF data in the horizontal plane for the first receiver.

    figure
    spectrum(s)

    Figure contains an axes object. The axes object with title Horizontal Plane Spectrum. Receiver 1., xlabel Frequency (Hz), ylabel Azimuth (degrees) contains an object of type surface.

    Compute and visualize the interaural level difference of the HRTF data in the horizontal plane.

    figure
    interauralLevelDifference(s)

    Figure contains an axes object. The axes object with title Horizontal Plane Interaural Level Difference, xlabel Frequency (Hz), ylabel Azimuth (degrees) contains an object of type surface.

    Compute and visualize the directivity of the HRTF data at 750 Hz and 1500 Hz in the horizontal plane.

    figure
    directivity(s,[750 1500])

    Figure contains an axes object with type polaraxes. The polaraxes object contains 2 objects of type line. These objects represent 750.000000 Hz, 1500.000000 Hz.

    More About

    expand all

    Version History

    Introduced in R2023b