-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_order.m
36 lines (30 loc) · 1 KB
/
check_order.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function [n_out, w, trivalwin] = check_order(n_in)
%CHECK_ORDER Checks the order passed to the window functions.
% [N,W,TRIVALWIN] = CHECK_ORDER(N_ESTIMATE) will round N_ESTIMATE to the
% nearest integer if it is not already an integer. In special cases (N is
% [], 0, or 1), TRIVALWIN will be set to flag that W has been modified.
w = [];
trivalwin = 0;
if ~(isnumeric(n_in) && isfinite(n_in))
error(generatemsgid('InvalidOrder'), 'The order N must be finite.');
end
% Special case of negative orders:
if n_in < 0
error(generatemsgid('InvalidOrder'), 'Order cannot be less than zero.');
end
% Check if order is already an integer or empty
% If not, round to nearest integer.
if isempty(n_in) || n_in == floor(n_in)
n_out = n_in;
else
n_out = round(n_in);
warning(generatemsgid('InvalidOrder'), 'Rounding order to nearest integer.');
end
% Special cases:
if isempty(n_out) || n_out == 0
w = zeros(0, 1); % Empty matrix: 0-by-1
trivalwin = 1;
elseif n_out == 1
w = 1;
trivalwin = 1;
end