Skip to content
This repository was archived by the owner on Jun 7, 2025. It is now read-only.

Commit 9b060ab

Browse files
committed
Added tuckeywin function
1 parent f7bcf01 commit 9b060ab

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

check_order.m

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

plot_norm_matrix.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function plot_norm_matrix(m, mt, mf, t, acc, regname)
3535
end
3636

3737
%% Plot matrix
38-
figure();
38+
f = figure();
39+
set(f, 'Visible', 'off');
3940

4041
%% Plot matrix
4142
subplot(2, 1, 1);
@@ -58,5 +59,9 @@ function plot_norm_matrix(m, mt, mf, t, acc, regname)
5859
xlim([0, t(end)]);
5960
grid on;
6061

62+
%% Show plot
63+
set(f, 'Visible', 'on');
64+
movegui(f, 'center');
65+
6166
end
6267

tukeywin.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function w = tukeywin(n, r)
2+
%TUKEYWIN Tukey window.
3+
error(nargchk(1, 2, nargin, 'struct')); %#ok<NCHKN>
4+
5+
% Default value for R parameter.
6+
if nargin < 2 || isempty(r)
7+
r = 0.500;
8+
end
9+
10+
[n, w, trivialwin] = check_order(n);
11+
if trivialwin, return, end
12+
13+
if r <= 0
14+
w = ones(n, 1);
15+
elseif r >= 1
16+
w = hann(n);
17+
else
18+
t = linspace(0, 1, n)';
19+
% Defines period of the taper as 1/2 period of a sine wave.
20+
per = r / 2;
21+
tl = floor(per*(n - 1)) + 1;
22+
th = n - tl + 1;
23+
% Window is defined in three sections: taper, constant, taper
24+
w = [((1 + cos(pi/per*(t(1:tl) - per))) / 2); ones(th-tl-1, 1); ((1 + cos(pi/per*(t(th:end) - 1 + per))) / 2)];
25+
end

0 commit comments

Comments
 (0)