Home > SUpDEq-v5.0.0 > supdeq_limitEqDataset.m

supdeq_limitEqDataset

PURPOSE ^

% SUpDEq - Spatial Upsampling by Directional Equalization

SYNOPSIS ^

function eqDataset_limited = supdeq_limitEqDataset(eqDataset, Nmax, radius, safetyMargin, fade)

DESCRIPTION ^

% SUpDEq - Spatial Upsampling by Directional Equalization

 function eqDataset_limited = supdeq_limitEqDataset(eqDataset, Nmax, radius, safetyMargin, fade)

 This function can be used to limit the equalization in frequency domain
 dependent on Nmax of the sparse HRTF set. Below the specific aliasing 
 frequency fA, the eqDataset will be set to 0, and thus the subsequent
 equalization will have no effect in this frequency range, resulting in 
 normal SH interpolation below fA. N = 0 is not affected by the limiting!

 IMPORTANT (1): If limitEq is applied for equalization using supdeq_eq, 
 it must also be applied for de-equalization using supdeq_deq!

 IMPORTANT (2): As fA depends on the radius, and the transition between 
 normal SH interpolation and SUpDEq processing should be the same in the
 equalization and de-equalization, the radius (of the eqDataset) can be
 passed here. Thus, if a different radius is applied for de-equalization,
 the limiting of the deqDataset should be done based on the radius of the
 eqDataset.

 Output:
 eqDataset_limited     - Limited eqDataset      

 Input:        
 eqDataset             - eqDataset struct obtained with supdeq_getEqDataset
 Nmax                  - Maximum spatial order N of the sparse HRTF set
 radius                - Optionally, the radius can be passed if fA should
                         be calculated based on another radius than 
                         specified in the eqDataset struct. This can be 
                         usefull, if the deqDataset has a different radius,
                         but the limiting should affect the dataset in the 
                         exact same frequency range (see important hints).
                         If the radius is not passed, the values specified 
                         in the eqDataset struct will be applied.
 safteyMargin          - Boolean to choose if safety margin (third-octave 
                         below fA) is applied or not. 
                         Default: true
 fade                  - Boolean to choose whether to apply a fade from fA
                         to fA/(2^1/3) or not
                         Default: false (to be compatabile with Arend et al. 2021)
                         Only applies if safteyMargin = true

 Dependencies: -

 (C) 2019 by JMA, Johannes M. Arend
             CP,  Christoph Pörschmann
             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 % function eqDataset_limited = supdeq_limitEqDataset(eqDataset, Nmax, radius, safetyMargin, fade)
0004 %
0005 % This function can be used to limit the equalization in frequency domain
0006 % dependent on Nmax of the sparse HRTF set. Below the specific aliasing
0007 % frequency fA, the eqDataset will be set to 0, and thus the subsequent
0008 % equalization will have no effect in this frequency range, resulting in
0009 % normal SH interpolation below fA. N = 0 is not affected by the limiting!
0010 %
0011 % IMPORTANT (1): If limitEq is applied for equalization using supdeq_eq,
0012 % it must also be applied for de-equalization using supdeq_deq!
0013 %
0014 % IMPORTANT (2): As fA depends on the radius, and the transition between
0015 % normal SH interpolation and SUpDEq processing should be the same in the
0016 % equalization and de-equalization, the radius (of the eqDataset) can be
0017 % passed here. Thus, if a different radius is applied for de-equalization,
0018 % the limiting of the deqDataset should be done based on the radius of the
0019 % eqDataset.
0020 %
0021 % Output:
0022 % eqDataset_limited     - Limited eqDataset
0023 %
0024 % Input:
0025 % eqDataset             - eqDataset struct obtained with supdeq_getEqDataset
0026 % Nmax                  - Maximum spatial order N of the sparse HRTF set
0027 % radius                - Optionally, the radius can be passed if fA should
0028 %                         be calculated based on another radius than
0029 %                         specified in the eqDataset struct. This can be
0030 %                         usefull, if the deqDataset has a different radius,
0031 %                         but the limiting should affect the dataset in the
0032 %                         exact same frequency range (see important hints).
0033 %                         If the radius is not passed, the values specified
0034 %                         in the eqDataset struct will be applied.
0035 % safteyMargin          - Boolean to choose if safety margin (third-octave
0036 %                         below fA) is applied or not.
0037 %                         Default: true
0038 % fade                  - Boolean to choose whether to apply a fade from fA
0039 %                         to fA/(2^1/3) or not
0040 %                         Default: false (to be compatabile with Arend et al. 2021)
0041 %                         Only applies if safteyMargin = true
0042 %
0043 % Dependencies: -
0044 %
0045 % (C) 2019 by JMA, Johannes M. Arend
0046 %             CP,  Christoph Pörschmann
0047 %             TH Köln - University of Applied Sciences
0048 %             Institute of Communications Engineering
0049 %             Department of Acoustics and Audio Signal Processing
0050 
0051 function eqDataset_limited = supdeq_limitEqDataset(eqDataset, Nmax, radius, safetyMargin, fade)
0052 
0053 if nargin < 3 || isempty(radius)
0054     radius = eqDataset.radius;
0055 end
0056 
0057 if nargin < 4 || isempty(safetyMargin)
0058     safetyMargin = true;
0059 end
0060 
0061 if nargin < 5 || isempty(fade)
0062     fade = false;
0063 end
0064 
0065 if isfield(eqDataset,'limited')
0066     if eqDataset.limited
0067         error('Input eqDataset already limited!');
0068     end
0069 end
0070 
0071 %Just a variable to check if equalizing should be applied
0072 noEq = false;
0073 
0074 %Get aliasing frequency fA (N ~ kr)
0075 fA = Nmax * eqDataset.c/ (2*pi*radius);
0076 %Check if fA is >= fs/2
0077 if fA >= eqDataset.f(end)
0078     noEq = true;
0079 end
0080 
0081 if safetyMargin
0082     %Lower by 1/3 octave to ensure distance to aliasing frequency
0083     fA_shift = fA/2^(1/3);
0084 else
0085     fA_shift = fA;
0086 end
0087 %Get corresponding index of frequency bins
0088 [~,fA_shift_bin] = min(abs(eqDataset.f-fA_shift));
0089 
0090 %Get eqDataset_limited
0091 eqDataset_limited = eqDataset;
0092 
0093 if ~noEq %If SUpDEq should be partly applied
0094     
0095     if safetyMargin && ~fade %Without fade
0096         %Set all SH coefficients for N > 0 to 0
0097         eqDataset_limited.Hl_nm(2:end,1:fA_shift_bin)=0;
0098         eqDataset_limited.Hr_nm(2:end,1:fA_shift_bin)=0;
0099     end
0100     
0101     if safetyMargin && fade %With fade from fA_shift to fA
0102         [~,fA_bin] = min(abs(eqDataset.f-fA));
0103         
0104         ramp = linspace(0,1,abs(fA_bin-fA_shift_bin)+1);
0105         
0106         eqDataset_limited.Hl_nm(2:end,1:fA_shift_bin-1)=0;
0107         eqDataset_limited.Hl_nm(2:end,fA_shift_bin:fA_bin)=eqDataset_limited.Hl_nm(2:end,fA_shift_bin:fA_bin).*ramp;
0108         eqDataset_limited.Hr_nm(2:end,1:fA_shift_bin-1)=0;
0109         eqDataset_limited.Hr_nm(2:end,fA_shift_bin:fA_bin)=eqDataset_limited.Hr_nm(2:end,fA_shift_bin:fA_bin).*ramp;
0110     end
0111     
0112 else %If fA is > fs/2 and SUpDEq does not need to be applied
0113     %Note: Actually, in this case SH interpolation without any equalization is
0114     %perfectly fine anyway ;-).
0115 
0116     %Set all SH coefficients for N > 0 to 0
0117     eqDataset_limited.Hl_nm(2:end,1:end)=0;
0118     eqDataset_limited.Hr_nm(2:end,1:end)=0;
0119 end
0120 
0121 %Write some infos in new struct eqDataset_limited
0122 eqDataset_limited.limited = true;
0123 eqDataset_limited.limitInfo.Nmax = Nmax;
0124 eqDataset_limited.limitInfo.appliedRadius = radius;
0125 eqDataset_limited.limitInfo.fA = fA;
0126 if ~noEq
0127     eqDataset_limited.limitInfo.fA_shift = fA_shift;
0128     if safetyMargin && fade
0129         eqDataset_limited.limitInfo.fade = true;
0130     end
0131 else
0132     eqDataset_limited.limitInfo.noEq = noEq;
0133 end
0134 
0135 fprintf('eqDataset limited depending on Nmax = %d\n',Nmax);

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