function b = lowpasslband(N,L,Win)
%LOWPASSLBAND  Design an L-th band N-th order windowed FIR lowpass filter.

%   Copyright 1999-2023 The MathWorks, Inc.

arguments
    N (1,1) {mustBeReal, mustBeInteger, mustBeNonnegative, mustBeFinite}
    L (1,1) {mustBeReal, mustBeInteger, mustBeNonnegative, mustBeFinite}
    Win {mustBeNumeric}
end

%#codegen

% Check for even order
coder.internal.errorIf(logical(rem(N,2)),'dsp:lowpasslband:MustBeEven');

% Make sure window is a row
Win = Win(:).';

% Generate a discrete-time vector
M = cast(floor(N/2),like=Win);

if coder.target('MATLAB')
    n = -M:M; 
else
    n = zeros(1,N+1,like=Win);
    for k=1:N+1
        n(k)=k-M-1;
    end
end

% Change variable, m = n/L, to be able to use sinc function
m = n./L;

% Generate the sinc function and window it
b = 1./L.*Win.*sinc(m);

% Make sure zeros are exact
b(M+1+L:L:end) = 0;
b(M+1-L:-L:1) = 0;

% EOF

