Skip to content
Snippets Groups Projects
Commit dbe64773 authored by Achilles Kappis's avatar Achilles Kappis
Browse files

Improved speed and clarity of code for the winSincFracDel.m and update date

parent 35787749
No related branches found
No related tags found
1 merge request!3Update to v0.2.3
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
% Author: Achilles Kappis % Author: Achilles Kappis
% e-mail: axilleaz@protonmail.com % e-mail: axilleaz@protonmail.com
% %
% Date: 17/04/2024 (DD/MM/YYYY) % Date: 13/08/2024 (DD/MM/YYYY)
% %
% Copyright: MIT % Copyright: MIT
% -------------------------------------------------- % --------------------------------------------------
...@@ -133,43 +133,43 @@ function [sincFilt, causDel, dSig] = winSincFracDel(del, len, winFun, sig, sigLe ...@@ -133,43 +133,43 @@ function [sincFilt, causDel, dSig] = winSincFracDel(del, len, winFun, sig, sigLe
sigLen = "Full"; sigLen = "Full";
end end
% ====================================================
% Calculate some parameters
% ====================================================
fracDel = del - abs(rem(intDel, 1)); % Fractional part of the delay
% ==================================================== % ====================================================
% Generate FIR filter for fractional 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 causDel = -idx(1); % The causal delay of the filter
sincFilt = sinc(idx - del); % Calculate the filter sincFilt = sinc(idx - fracDel); % Calculate the filter
% ==================================================== % ====================================================
% Apply windowing % Apply windowing
% ==================================================== % ====================================================
fracDel = abs(rem(del, 1)); % Total filter delay
% Generate window % Generate window
if isstring(winFun) if isstring(winFun)
switch lower(winFun) switch lower(winFun)
case "rectangular"
win = ones(length(idx), 1);
case "hann" case "hann"
win = sin(pi * (idx - fracDel)/len).^2; win = sin(pi * (idx - fracDel + causDel + 1)/len).^2;
case "hamming" case "hamming"
alpha = 25/46; alpha = 25/46;
win = alpha - (1 - alpha) * cos(2 * pi * (idx - fracDel)/len); win = alpha - (1 - alpha) * cos(2 * pi * (idx - fracDel + causDel + 1)/len);
otherwise % Rectangular
win = ones(length(idx), 1);
end end
else else
% Kaiser window % 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 end
% Shift window function to centre on sinc's peak % Apply window to the filter
if ~isscalar(winFun) sincFilt = sincFilt .* win;
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);
% ==================================================== % ====================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment