1
function [sr,repos,Lc]=filterbankreassign(s,tgrad,fgrad,a,var)
3
%@deftypefn {Function} filterbankreassign
5
%FILTERBANKREASSIGN Reassign filterbank spectrogram
6
% Usage: sr = filterbankreassign(s,tgrad,fgrad,a,cfreq);
7
% sr = filterbankreassign(s,tgrad,fgrad,a,g);
8
% [sr,repos,Lc] = filterbankreassign(...);
11
% s : Spectrogram to be reassigned.
12
% tgrad : Instantaneous frequency relative to original position.
13
% fgrad : Group delay relative to original position.
14
% a : Vector of time steps.
15
% cfreq : Vector of relative center frequencies in ]-1,1].
18
% sr : Reassigned filterbank spectrogram.
19
% repos : Reassigned positions.
20
% Lc : Subband lengths.
22
% FILTERBANKREASSIGN(s,a,tgrad,fgrad,cfreq) will reassign the values of
23
% the filterbank spectrogram s using the group delay fgrad and
24
% instantaneous frequency tgrad. The time-frequency sampling
25
% pattern is determined from the time steps a and the center
28
% FILTERBANKREASSIGN(s,a,tgrad,fgrad,g) will do the same thing except
29
% the center frequencies are estimated from a set of filters g.
31
% [sr,repos,Lc]=FILTERBANKREASSIGN(...) does the same thing, but in addition
32
% returns a vector of subband lengths Lc (Lc = cellfun(@numel,s))
33
% and cell array repos with sum(Lc) elements. Each element corresponds
34
% to a single coefficient obtained by cell2mat(sr) and it is a vector
35
% of indices identifying coefficients from cell2mat(s) assigned to
36
% the particular time-frequency position.
38
% The arguments s, tgrad and fgrad must be cell-arrays of vectors
39
% of the same lengths. Arguments a and cfreq or g must have the
40
% same number of elements as the cell arrays with coefficients.
45
% This example shows how to reassign a ERB filterbank spectrogram:
47
% % Genrate 3 chirps 1 second long
48
% L = 44100; fs = 44100; l = 0:L-1;
50
% f = sin(2*pi*(l/35+(l/300).^2)) + ...
51
% sin(2*pi*(l/10+(l/300).^2)) + ...
52
% sin(2*pi*(l/5-(l/450).^2));
55
% % Create ERB filterbank
56
% [g,a,fc]=erbfilters(fs,L,'fractional','spacing',1/12,'warped');
58
% % Compute phase gradient
59
% [tgrad,fgrad,cs,c]=filterbankphasegrad(f,g,a);
60
% % Do the reassignment
61
% sr=filterbankreassign(cs,tgrad,fgrad,a,cent_freqs(fs,fc));
62
% figure(1); subplot(211);
63
% plotfilterbank(cs,a,fc,fs,60);
64
% title('ERBlet spectrogram of 3 chirps');
66
% plotfilterbank(sr,a,fc,fs,60);
67
% title('Reassigned ERBlet spectrogram of 3 chirps');
71
% N. Holighaus, Z. Průša, and P. L. Soendergaard. New ideas in
72
% reassignment: General time-frequency filter banks, sampling and
73
% processing. IEEE Signal Processing Letters, submitted, 2015.
76
%@strong{Url}: @url{http://ltfat.github.io/doc/filterbank/filterbankreassign.html}
77
%@seealso{filterbankphasegrad, gabreassign}
80
% Copyright (C) 2005-2015 Peter L. Soendergaard <peter@sonderport.dk>.
81
% This file is part of LTFAT version 2.1.0
83
% This program is free software: you can redistribute it and/or modify
84
% it under the terms of the GNU General Public License as published by
85
% the Free Software Foundation, either version 3 of the License, or
86
% (at your option) any later version.
88
% This program is distributed in the hope that it will be useful,
89
% but WITHOUT ANY WARRANTY; without even the implied warranty of
90
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91
% GNU General Public License for more details.
93
% You should have received a copy of the GNU General Public License
94
% along with this program. If not, see <http://www.gnu.org/licenses/>.
96
% AUTHOR : Nicki Holighaus.
99
complainif_notenoughargs(nargin,5,'FILTERBANKREASSIGN');
101
if isempty(s) || ~iscell(s)
102
error('%s: s should be a nonempty cell array.',upper(mfilename));
105
if isempty(tgrad) || ~iscell(tgrad)
106
error('%s: tgrad should be a nonempty cell array.',upper(mfilename));
109
if isempty(fgrad) || ~iscell(fgrad)
110
error('%s: fgrad should be a nonempty cell array.',upper(mfilename));
113
if any(cellfun(@(sEl,tEl,fEl) ~isvector(sEl) || ~isvector(tEl) || ...
114
~isvector(fEl), s,tgrad,fgrad))
115
error('%s: s, tgrad, frad must be cell arrays of numeric vectors.',...
119
if any(size(s)~=size(tgrad)) || any(size(s)~=size(fgrad)) || ...
120
any(cellfun(@(sEl,tEl,fEl) any(size(sEl)~=size(tEl)) ...
121
|| any(size(sEl)~=size(fEl)),...
123
error('%s: s, tgrad, frad does not have the same format.',upper(mfilename));
127
W = cellfun(@(sEl)size(sEl,2),s);
129
error('%s: Only one-channel signals are supported.',upper(mfilename));
135
% Number of elements in channels
136
Lc = cellfun(@(sEl)size(sEl,1),s);
139
a=comp_filterbank_a(a,M);
142
% Check if a comply with subband lengths
144
if any(abs(L-L(1))>1e-6)
145
error(['%s: Subsampling factors and subband lengths do not ',...
146
'comply.'],upper(mfilename));
150
% Determine center frequencies
151
if isempty(var) || numel(var)~=M || ~isvector(var) && ~iscell(var)
152
error(['%s: cfreq must be length-M numeric vector or a cell-array ',...
153
'containg M filters.'],upper(mfilename));
156
cfreq = cent_freqs(var,L);
162
% Do the computations
164
[sr,repos] = comp_filterbankreassign(s,tgrad,fgrad,a,cfreq);
166
sr = comp_filterbankreassign(s,tgrad,fgrad,a,cfreq);