Skip to content

Commit

Permalink
Update get_PNLT.m
Browse files Browse the repository at this point in the history
-  in case <PNLTM_idx> is closer from the lower or higher boundaries of  the time vector, the bandsharing adjustment may not possible.

- introduced conditions to check whether indices are valid

- truncate DeltaB  = 0 if bandsharing adjustment  is not possible.
  • Loading branch information
ggrecow committed Jan 13, 2025
1 parent 3ffae22 commit af2a1b2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions psychoacoustic_metrics/EPNL_FAR_Part36/helper/get_PNLT.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,27 @@

if size(Cmax,1)~=1 % workaround to run the <run_validation_tone_correction.m> code, where only one time-step is considered

Cavg = sum( [Cmax(PNLTM_idx - 2), Cmax(PNLTM_idx - 1), Cmax(PNLTM_idx),...
Cmax(PNLTM_idx + 1), Cmax(PNLTM_idx + 2)] )/5;
% in case <PNLTM_idx> is closer from the lower or higher boundaries of
% the time vector, the bandsharing adjustment may not possible

if Cavg > Cmax(PNLTM_idx)
DeltaB = Cavg*Cmax(PNLTM_idx);
else
indicesToAccess = [ (PNLTM_idx - 2), (PNLTM_idx - 1), (PNLTM_idx + 1), (PNLTM_idx + 2)]; % get indices to access

isValid = indicesToAccess > 0 & indicesToAccess <= length(PNLT); % Logical condition to check for valid indices

if all(isValid~=0) % runs only if all indices are valid

Cavg = sum( [Cmax(PNLTM_idx - 2), Cmax(PNLTM_idx - 1), Cmax(PNLTM_idx),...
Cmax(PNLTM_idx + 1), Cmax(PNLTM_idx + 2)] )/5;

if Cavg > Cmax(PNLTM_idx)
DeltaB = Cavg*Cmax(PNLTM_idx);
else
DeltaB = 0;
end

else % there are empty indices: Bandsharing adjustment to PNLTM not possible
DeltaB = 0;
warning( 'Bandsharing adjustment to PNLTM not possible. DeltaB truncated to zero.' );
end

% apply adjustment
Expand Down

0 comments on commit af2a1b2

Please sign in to comment.