Home > SUpDEq-v5.0.0 > supdeq_demo_DVF.m

supdeq_demo_DVF

PURPOSE ^

% SUpDEq - Spatial Upsampling by Directional Equalization

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

% SUpDEq - Spatial Upsampling by Directional Equalization
  
 script supdeq_demo_DVF

 This script presents how SUpDEq can be applied as a distance variation
 function (DVF). A (sparse) far-field HRTF set is transformed to (dense)
 near-field HRTF set. 

 Reference:
 J. M. Arend and C. Pörschmann, "Synthesis of Near-Field HRTFs by Directional 
 Equalization of Far-Field Datasets," in Proceedings of the 45th DAGA, 2019, pp. 1454?1457.

 (C) 2018 by JMA, Johannes M. Arend
             TH Köln - University of Applied Sciences
             Institute of Communications Engineering
             Department of Acoustics and Audio Signal Processing

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% SUpDEq - Spatial Upsampling by Directional Equalization
0002 %
0003 % script supdeq_demo_DVF
0004 %
0005 % This script presents how SUpDEq can be applied as a distance variation
0006 % function (DVF). A (sparse) far-field HRTF set is transformed to (dense)
0007 % near-field HRTF set.
0008 %
0009 % Reference:
0010 % J. M. Arend and C. Pörschmann, "Synthesis of Near-Field HRTFs by Directional
0011 % Equalization of Far-Field Datasets," in Proceedings of the 45th DAGA, 2019, pp. 1454?1457.
0012 %
0013 % (C) 2018 by JMA, Johannes M. Arend
0014 %             TH Köln - University of Applied Sciences
0015 %             Institute of Communications Engineering
0016 %             Department of Acoustics and Audio Signal Processing
0017 
0018 %% (1) - Load reference HRTF dataset (stored as SH-coefficients in spherical harmonics domain)
0019 %See small script "get_HRIRs_sfd_Nx.m" in materials folder to see how the
0020 %dataset was obtained based on the "HRIR_L2702_NFxxx.sofa" HRIR dataset of a
0021 %Neumann KU100 dummy head. The reference dataset is only needed for
0022 %comparison with the final de-equalized dataset...
0023 
0024 referenceHRTFdataset = importdata('HRIRs_NF050_sfd_N44.mat');
0025 NeqDataset = 44; %According to referenceHRTFdataset
0026 
0027 %% (2) - Load sparse HRTF dataset (stored as FFT-bins in Fourier domain)
0028 %This is just an example. You could use any sparse HRTF dataset here! Also
0029 %have a look at the script "get_sparse_HRTF_set.m" in materials folder to
0030 %see how the sparse datasets are obtained.
0031 
0032 %Here, we use a sparse HRTF daset with only 38 sample points (Lebedev grid)
0033 %The sampling grid as well as the highste possible transform oder N are
0034 %required for the equalization! It is saved in the struct here, but it
0035 %could also be passed separately to the function "subdeq_eq"
0036 load('sparseHRTFdataset_DVF_L38.mat');
0037 
0038 %Optionally, a sparse HRIR dataset in SOFA format can be loaded. With the
0039 %function supdeq_sofa2hrtf, the SOFA file will be transformed to
0040 %frequency domain and saved in a struct as used by the SUpDEq toolbox
0041 %(compare to the structs 'sparseHRTFdataset'). FFToversize and Nmax have to
0042 %be defined manually now, because SOFA does not support such meta data.
0043 %Furthermore, the sampling grid in SOFA does not support sampling weights,
0044 %which can be useful for spherical Fourier / SH transform. Thus, optionally
0045 %a sampling grid with weigths can be passed, which will than be stored in
0046 %the struct. Otherwise, the sampling grid stored in the SOFA file will be
0047 %written to the HRTF struct.
0048 SOFAinput = false;
0049 if SOFAinput
0050     %Load sparse HRIR dataset in SOFA format
0051     sparseHRIRdataset_SOFA = SOFAload('sparseHRIRdataset_DVF_L38.sofa');
0052     %Transform to sparseHRTFdataset struct with pre-defined samplingGrid
0053     %(Lebedev grid with 38 nodes here), Nmax = 4, and FFToversize = 4.
0054     sparseHRTFdataset = supdeq_sofa2hrtf(sparseHRIRdataset_SOFA,4,supdeq_lebedev(38),4);
0055 end
0056 
0057 %% (3) - Get equalization dataset (SH-coefficients)
0058 %The eqDataset describes the sound pressure distribution on a sphere
0059 %Use N = 44 and defaults: earDistance = 0.165m, NFFT = 512, fs = 48000;
0060 eqDataset = supdeq_getEqDataset(NeqDataset);
0061 
0062 %% (4) - Perform equalization
0063 %Here, the sparse HRTF dataset is equalized with the eqDataset. The
0064 %equalized HRTF are transformed to the SH-domain again with the maximal
0065 %order N which is possible with the sparse sampling grid.
0066 %N and the sparse sampling grid are part of the sparseHRTFdataset struct
0067 sparseSamplingGrid = sparseHRTFdataset.samplingGrid;
0068 Nsparse = sparseHRTFdataset.Nmax;
0069 
0070 eqHRTFdataset = supdeq_eq(sparseHRTFdataset,eqDataset,Nsparse,sparseSamplingGrid);
0071 
0072 %% (5) - Perform de-equalization
0073 %Here, the sparse equalized HRTF dataset is de-equalized with the
0074 %deqDataset. This is done on a dense spatial sampling grid. The results is a
0075 %dense HRTF/HRIR dataset. To adapt the distance (apply the DVF), the
0076 %deqDataset is generated based on a spherical wave at the target distance
0077 
0078 %First, define dense spatial sampling grid. Here, we use the lebedev grid
0079 %with 2702 points again (same as the reference HRIR dataset).
0080 %The highest stable grid order here is N = 44.
0081 denseSamplingGrid = supdeq_lebedev(2702);
0082 Ndense = 44;
0083 
0084 %Now, generate deqDataset for targetDistance
0085 targetDistance = 0.50; %Target distance for the near-field HRTFs in m
0086 %Use defaults: earDistance = 0.165m, NFFT = 512, fs = 48000
0087 deqDataset = supdeq_getEqDataset(NeqDataset,[],[],[],1,targetDistance);
0088 
0089 %Perform de-equalization. Apply head and tail window (8 and 32 samples
0090 %respectively) to de-equalized HRIRs/HRTFs. The directions of the
0091 %denseSamplingGrid are re-calculated automatically in supdeq_deq
0092 %to consider the acoustic parallax effect which occurs in the near field
0093 [denseHRTFdataset, denseHRIRdataset, denseHRTFdataset_sh] = supdeq_deq(eqHRTFdataset, deqDataset, Ndense, denseSamplingGrid,[8,32],0.99);
0094 
0095 %% (6) - Optional: Save as SOFA object
0096 %Use sourceDistance = targetDistance and defaults: fs = 48000, earDistance = 0.165m
0097 denseHRIRdataset_SOFA = supdeq_writeSOFAobj(denseHRIRdataset.HRIR_L,denseHRIRdataset.HRIR_R,denseSamplingGrid,[],[],targetDistance);
0098 
0099 %% (7) - Optional: Plot HRIRs
0100 %Get HRIRs from reference dataset and de-equalized dense dataset. In this
0101 %example, we chose a lateral source, because most differences between the
0102 %reference and the de-equalized HRIRs occure at the contralateral ear.
0103 azPlot = 0;
0104 elPlot = 90;
0105 [hrir_ref(:,1),hrir_ref(:,2)] = supdeq_getArbHRIR(referenceHRTFdataset,[azPlot,elPlot]);
0106 [hrir_deq(:,1),hrir_deq(:,2)] = supdeq_getArbHRIR(denseHRTFdataset_sh,[azPlot,elPlot]);
0107 
0108 %Plot left and right channel of reference and deq set in two plots with
0109 %32 x FFT oversampling
0110 supdeq_plotIR(hrir_ref(:,1),hrir_deq(:,1),[],[],32);
0111 supdeq_plotIR(hrir_ref(:,2),hrir_deq(:,2),[],[],32);
0112 
0113 %% (8) - Optional: Listen to the results
0114 %Here, you can listen to a short drums sequence, spatialized with a
0115 %reference HRIR and a de-equalized HRIR
0116 
0117 %Load drums test signal
0118 [testSignal,fsTestSignal] = audioread('drums.wav');
0119 
0120 %Define az and el for playback
0121 azPlayback = 0;
0122 elPlayback = 90;
0123 
0124 %Convolve with reference HRIR and play back
0125 supdeq_listen(referenceHRTFdataset,testSignal,[azPlayback,elPlayback]);
0126 %Wait for length of test-signal
0127 pause(length(testSignal)/fsTestSignal+0.05);
0128 %Convolve with de-equalized HRIR and play back
0129 supdeq_listen(denseHRTFdataset_sh,testSignal,[azPlayback,elPlayback]);
0130 
0131 %% (9) - Optional: Technical Evaluation
0132 
0133 %Perform test of sagittal plane localization with default spatial sampling
0134 %grid
0135 spLocalization = supdeq_testSPlocalization(denseHRTFdataset_sh, referenceHRTFdataset);
0136 
0137 %Perform test of horizontal plane localizatoin with default spatial
0138 %sampling grid
0139 hpLocalization = supdeq_testHPlocalization(denseHRTFdataset_sh, referenceHRTFdataset);
0140 
0141 %Calculate spectral differences with default spatial sampling grid and
0142 %make simple plot
0143 specDifferences = supdeq_calcSpectralDifference(denseHRTFdataset_sh, referenceHRTFdataset,[],[],false,true);
0144 
0145 %Calculate spectral differences in auditory bands with default spatial
0146 %sampling grid and make simple plot
0147 specDifferences_auditoryBands = supdeq_calcSpectralDifference(denseHRTFdataset_sh, referenceHRTFdataset,[],[],true,true);
0148 
0149 %Calculate energy per order N and make simple plot
0150 energyPerOrder = supdeq_calcEnergyPerOrder(denseHRTFdataset_sh,true);

Generated on Wed 30-Nov-2022 14:15:00 by m2html © 2005