19
19
% NAT2FREQORDER(wt,nodes) does the same but works only with nodes
22
% REMARK: The function is self invertible.
22
% NAT2FREQORDER(...,'rev') changes the frequency ordering back to
26
%@strong{Url}: @url{http://ltfat.sourceforge.net/doc/wavelets/wfbtmanip/nat2freqOrder.php}
27
%@strong{Url}: @url{http://ltfat.github.io/doc/wavelets/wfbtmanip/nat2freqOrder.html}
27
28
%@seealso{wfbtinit, wfbtmultid, nodebforder}
30
% Copyright (C) 2005-2014 Peter L. Soendergaard <soender@users.sourceforge.net>.
31
% This file is part of LTFAT version 2.0.1
31
% Copyright (C) 2005-2015 Peter L. Soendergaard <peter@sonderport.dk>.
32
% This file is part of LTFAT version 2.1.0
33
34
% This program is free software: you can redistribute it and/or modify
34
35
% it under the terms of the GNU General Public License as published by
52
53
varargin(strcmp('rev',varargin)) = [];
56
bftreepath = nodeBForder(0,wt);
55
58
if isempty(varargin)
56
% Work with the whole tree
57
treePath = nodeBForder(0,wt);
59
treePath = treePath(2:end);
59
treePath = bftreepath(2:end);% skip root
61
61
% Work with specified nodes only
62
62
nodes = varargin{1};
69
69
% Dual-tree complex wavelet packets require some more tweaking.
70
70
if isfield(wt,'dualnodes')
71
72
locIdxs = arrayfun(@(tEl) find(wt.children{wt.parents(tEl)}==tEl,1),treePath);
72
73
treeNodes = treePath(rem(locIdxs,2)~=1);
73
74
% Root was removed so the following will not fail
92
% Get loc. index of nodes
93
locIdxs = arrayfun(@(tEl) find(wt.children{wt.parents(tEl)}==tEl,1),treePath);
95
% Get only nodes connected to a high-pass output
96
treeNodes = treePath(rem(locIdxs,2)~=1);
99
% now for the filter reordering
100
wt.nodes{nodeId}.g = wt.nodes{nodeId}.g(end:-1:1);
101
wt.nodes{nodeId}.h = wt.nodes{nodeId}.h(end:-1:1);
102
wt.nodes{nodeId}.a = wt.nodes{nodeId}.a(end:-1:1);
104
% Do the same with the dual tree if it exists
105
if isfield(wt,'dualnodes')
106
wt.dualnodes{nodeId}.g = wt.dualnodes{nodeId}.g(end:-1:1);
107
wt.dualnodes{nodeId}.h = wt.dualnodes{nodeId}.h(end:-1:1);
108
wt.dualnodes{nodeId}.a = wt.dualnodes{nodeId}.a(end:-1:1);
92
% Array indexed by nodeId
93
reordered = zeros(size(bftreepath));
98
ch = postpad(wt.children{nodeId},numel(wt.nodes{nodeId}.g));
100
if reordered(nodeId) && rem(numel(ch),2)==1
107
reordered(ch(m+1)) = 1;
115
for nodeId=treePath(logical(reordered(treePath)))
116
wt = reorderFilters(nodeId,wt);
119
function wt = reorderFilters(nodeId,wt)
120
% now for the filter reordering
121
wt.nodes{nodeId}.g = wt.nodes{nodeId}.g(end:-1:1);
122
wt.nodes{nodeId}.h = wt.nodes{nodeId}.h(end:-1:1);
123
wt.nodes{nodeId}.a = wt.nodes{nodeId}.a(end:-1:1);
125
% Do the same with the dual tree if it exists
126
if isfield(wt,'dualnodes')
127
wt.dualnodes{nodeId}.g = wt.dualnodes{nodeId}.g(end:-1:1);
128
wt.dualnodes{nodeId}.h = wt.dualnodes{nodeId}.h(end:-1:1);
129
wt.dualnodes{nodeId}.a = wt.dualnodes{nodeId}.a(end:-1:1);