diff --git a/Signal Processing/Generic/MATLAB/Functions/winSincFracDel.m b/Signal Processing/Generic/MATLAB/Functions/winSincFracDel.m index 3455345b0c309c557a8faf4eb5ea057f04228f51..5f8b3f4f02a69c2c45625db0c30c814476c8e5f4 100644 --- a/Signal Processing/Generic/MATLAB/Functions/winSincFracDel.m +++ b/Signal Processing/Generic/MATLAB/Functions/winSincFracDel.m @@ -3,7 +3,7 @@ % Author: Achilles Kappis % e-mail: axilleaz@protonmail.com % -% Date: 17/04/2024 (DD/MM/YYYY) +% Date: 13/08/2024 (DD/MM/YYYY) % % Copyright: MIT % -------------------------------------------------- @@ -133,43 +133,43 @@ function [sincFilt, causDel, dSig] = winSincFracDel(del, len, winFun, sig, sigLe sigLen = "Full"; end + + % ==================================================== + % Calculate some parameters + % ==================================================== + fracDel = del - abs(rem(intDel, 1)); % Fractional part of the delay + + % ==================================================== % Generate FIR filter for fractional delay % ==================================================== - idx = (-len + 1:len).'; % Filter sample indices + idx = floor(-len/2 + 1):floor(len/2); % Filter sample indices - causDel = -floor(idx(1)/2); % The causal delay of the filter - sincFilt = sinc(idx - del); % Calculate the filter + causDel = -idx(1); % The causal delay of the filter + sincFilt = sinc(idx - fracDel); % Calculate the filter % ==================================================== % Apply windowing % ==================================================== - fracDel = abs(rem(del, 1)); % Total filter delay - % Generate window if isstring(winFun) switch lower(winFun) + case "rectangular" + win = ones(length(idx), 1); case "hann" - win = sin(pi * (idx - fracDel)/len).^2; + win = sin(pi * (idx - fracDel + causDel + 1)/len).^2; case "hamming" alpha = 25/46; - win = alpha - (1 - alpha) * cos(2 * pi * (idx - fracDel)/len); - otherwise % Rectangular - win = ones(length(idx), 1); + win = alpha - (1 - alpha) * cos(2 * pi * (idx - fracDel + causDel + 1)/len); end else % Kaiser window - win = besseli(0, pi * winFun * sqrt(1 - (2 * (idx - del)/len).^2))/besseli(0, pi * winFun); + win = besseli(0, pi * winFun * sqrt(1 - (2 * (idx - fracDel)/len).^2))/besseli(0, pi * winFun); end - % Shift window function to centre on sinc's peak - if ~isscalar(winFun) - win = delayseq(win, floor(del) + causDel); - end - - % Apply window function and keep only the causal part up to the length of the filter - sincFilt = sincFilt(causDel + 1:causDel + len) .* win(causDel + 1:causDel + len); + % Apply window to the filter + sincFilt = sincFilt .* win; % ====================================================