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
Branches
Tags v1.0-rc2
1 merge request!3Update to v0.2.3
......@@ -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;
% ====================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment