Main Content

spectrum

HRTF power spectrum

Since R2024a

    Description

    example

    h = spectrum(s) returns the power spectrum of the HRTF measurements in the horizontal plane at zero elevation.

    example

    h = spectrum(s,Name=Value) specifies options using one or more name-value arguments.

    example

    [h,f] = spectrum(___) also returns the frequencies of the spectrum.

    [h,f,ang] = spectrum(___) also returns the angles corresponding to the measurements.

    example

    spectrum(___) with no output arguments plots the power spectrum.

    Examples

    collapse all

    Read in a SOFA file containing HRTF measurements.

    s = sofaread("ReferenceHRTF.sofa");

    Use spectrum to compute the power spectrum of the HRTF data in the horizontal plane at zero elevation for the first receiver.

    [h,f] = spectrum(s);

    Call spectrum with no output arguments to plot the power spectrum of the HRTF data in the horizontal plane for the first receiver.

    spectrum(s)

    Read in a SOFA file containing HRTF measurements.

    s = sofaread("ReferenceHRTF.sofa");

    Use spectrum to compute the power spectrum of the HRTF data in the horizontal plane offset by 7 degrees of elevation. See how the returned spectrum is empty because the SOFA file contains no measurements in the specified plane.

    h = spectrum(s,Plane="horizontal",PlaneOffsetAngle=7);
    size(h)
    ans = 1×2
    
            2048           0
    
    

    Call spectrum with InterpolateHRTF set to true to compute the spectrum using interpolated HRTF measurements corresponding to 100 uniformly-spaced points in the specified plane.

    h = spectrum(s,Plane="horizontal",PlaneOffsetAngle=7,InterpolateHRTF=true);
    size(h)
    ans = 1×2
    
            2048         100
    
    

    Call spectrum with no output arguments to plot the computed spectrum.

    spectrum(s,Plane="horizontal",PlaneOffsetAngle=7,InterpolateHRTF=true);

    Input Arguments

    collapse all

    SOFA object, specified as one of the following objects.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: spectrum(s, Plane="median")

    Indices of the receivers to use for the power spectrum, specified as a vector of positive integers.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Number of points in the spectrum, specified as a positive integer. For SimpleFreeFieldHRIR objects, the default value is max(2048,L), where L is the length of the HRTF impulse responses. For SimpleFreeFieldHRSOS objects, the default value is 2048.

    This argument does not apply to SimpleFreeFieldHRTF objects.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Plane to compute spectrum for, specified as "horizontal", "median", or "sagittal".

    Data Types: char | string

    Plane offset angle in degrees, specified as a value in the range [-90,90]. This angle specifies the offset by which the Plane is shifted.

    This argument only applies to the horizontal and sagittal planes. For the horizontal plane, the offset corresponds to the elevation angle. For the sagittal plane, the offset corresponds to the lateral angle.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Angle tolerance in degrees, specified as a positive scalar. The function computes the spectrum of measurements within the tolerance of the plane specified by Plane and PlaneOffsetAngle.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Use interpolated HRTF measurements, corresponding to 100 uniformly-spaced points in the specified plane, to compute the power spectrum. Set this argument to true if the plane specified by Plane, PlaneOffsetAngle, and AngleTolerance does not contain a sufficient number of HRTF measurements. The function uses the bilinear interpolation method.

    Data Types: logical

    Output Arguments

    collapse all

    Power spectrum computed from the HRTF data, returned as an N-by-M-by-R array, where:

    • N is the length of the spectrum.

    • M is the number of selected measurements.

    • R is the number of selected receivers defined by Receiver.

    Frequencies in Hz corresponding to the spectrum, returned as a vector of length N, where N is the length of the spectrum.

    Angles in degrees corresponding to the measurements used to compute the spectrum, returned as a vector. The interpretation of the angles depends on the specified Plane.

    • For the horizontal plane, the angles correspond to the azimuth.

    • For the median plane, the angles correspond to the elevation.

    • For the sagittal plane, the angles correspond to the polar angles.

    Version History

    Introduced in R2024a