~ubuntu-branches/ubuntu/wily/octave-ltfat/wily-proposed

« back to all changes in this revision

Viewing changes to inst/filterbank/filterbankreassign.m

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot, Rafael Laboissiere
  • Date: 2015-07-18 23:36:41 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20150718233641-jhuf3f551a3523qc
Tags: 2.1.0+dfsg-1
* Team upload.

[ Rafael Laboissiere ]
* Imported Upstream version 2.1.0+dfsg
* d/rules: Prevent unit testing on armhf and mips.
  This avoids FTBFS on theses architectures (see Bug#765545).
* Unit testing does not need X-window anymore
  + d/rules: Do not use xfvb-run to run the tests.
  + d/control: Drop xauth, xvfb, and gnuplot-nox from Build-Depends.
    Also, the versioned dependency on octave-pkg-dev is relaxed.
* Drop .jar file from upstream tarball, complying with the Debian Policy
  + d/copyright: Exclude file blockproc.jar
  + d/rules: Add get-orig-source target
  + d/watch: Mangle upstream version to cope with "+dfsg" tag
* Build blockproc.jar, which is deleted from the upstream tarball
  + d/rules: Add commands for building blockproc.jar
  + d/control: Build-depend on default-jdk
  + d/p/fix-path-of-included-makefile.patch: New patch
* Bump Standard-Versions to 3.9.6 (no changes needed)
* d/p/autoload-yes.patch: Remove patch (deprecated upstream)
* Bump Build-Depends on octave to >> 4.0.0~rc4-1 (for sndfile support)
* d/check.m: Avoid verbose output of unit tests
* d/watch: Add the repacksuffix option
* d/p/add-hardening-flags.patch: Drop patch (applied upstream)
* d/p/fix-path-of-included-makefile.patch: Drop patch (applied upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [sr,repos,Lc]=filterbankreassign(s,tgrad,fgrad,a,var)
 
2
%-*- texinfo -*-
 
3
%@deftypefn {Function} filterbankreassign
 
4
%@verbatim
 
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(...);
 
9
%
 
10
%   Input parameters:
 
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].
 
16
%      g     : Set of filters.
 
17
%   Output parameters:
 
18
%      sr    : Reassigned filterbank spectrogram.
 
19
%      repos : Reassigned positions.
 
20
%      Lc    : Subband lengths.
 
21
%
 
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 
 
26
%   frequencies cfreq. 
 
27
%
 
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.
 
30
%
 
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.
 
37
%
 
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.
 
41
%
 
42
%   Examples:
 
43
%   ---------
 
44
%
 
45
%   This example shows how to reassign a ERB filterbank spectrogram:
 
46
%
 
47
%     % Genrate 3 chirps 1 second long
 
48
%     L = 44100; fs = 44100; l = 0:L-1;
 
49
 
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));
 
53
%     f = 0.7*f';
 
54
%     
 
55
%     % Create ERB filterbank
 
56
%     [g,a,fc]=erbfilters(fs,L,'fractional','spacing',1/12,'warped');
 
57
%     
 
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');
 
65
%     subplot(212);  
 
66
%     plotfilterbank(sr,a,fc,fs,60);
 
67
%     title('Reassigned ERBlet spectrogram of 3 chirps');
 
68
%
 
69
%
 
70
%   References:
 
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.
 
74
%     
 
75
%@end verbatim
 
76
%@strong{Url}: @url{http://ltfat.github.io/doc/filterbank/filterbankreassign.html}
 
77
%@seealso{filterbankphasegrad, gabreassign}
 
78
%@end deftypefn
 
79
 
 
80
% Copyright (C) 2005-2015 Peter L. Soendergaard <peter@sonderport.dk>.
 
81
% This file is part of LTFAT version 2.1.0
 
82
%
 
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.
 
87
%
 
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.
 
92
%
 
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/>.
 
95
 
 
96
%   AUTHOR : Nicki Holighaus.
 
97
 
 
98
% Sanity checks
 
99
complainif_notenoughargs(nargin,5,'FILTERBANKREASSIGN');
 
100
 
 
101
if isempty(s) || ~iscell(s) 
 
102
    error('%s: s should be a nonempty cell array.',upper(mfilename));
 
103
end
 
104
 
 
105
if isempty(tgrad) || ~iscell(tgrad) 
 
106
    error('%s: tgrad should be a nonempty cell array.',upper(mfilename));
 
107
end
 
108
 
 
109
if isempty(fgrad) || ~iscell(fgrad) 
 
110
    error('%s: fgrad should be a nonempty cell array.',upper(mfilename));
 
111
end
 
112
 
 
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.',...
 
116
         upper(mfilename)); 
 
117
end
 
118
 
 
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)),...
 
122
                           s,tgrad,fgrad))
 
123
   error('%s: s, tgrad, frad does not have the same format.',upper(mfilename));   
 
124
end
 
125
 
 
126
 
 
127
W = cellfun(@(sEl)size(sEl,2),s);
 
128
if any(W>1)
 
129
   error('%s: Only one-channel signals are supported.',upper(mfilename)); 
 
130
end
 
131
 
 
132
% Number of channels
 
133
M = numel(s);
 
134
 
 
135
% Number of elements in channels
 
136
Lc = cellfun(@(sEl)size(sEl,1),s);
 
137
 
 
138
% Sanitize a
 
139
a=comp_filterbank_a(a,M);
 
140
a = a(:,1)./a(:,2);
 
141
 
 
142
% Check if a comply with subband lengths
 
143
L = Lc.*a;
 
144
if any(abs(L-L(1))>1e-6)
 
145
   error(['%s: Subsampling factors and subband lengths do not ',...
 
146
          'comply.'],upper(mfilename));
 
147
end
 
148
L = L(1);
 
149
 
 
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)); 
 
154
else
 
155
    if iscell(var)
 
156
       cfreq = cent_freqs(var,L);
 
157
    else
 
158
       cfreq = var;
 
159
    end
 
160
end
 
161
 
 
162
% Do the computations
 
163
if nargout>1
 
164
   [sr,repos] = comp_filterbankreassign(s,tgrad,fgrad,a,cfreq);
 
165
else
 
166
   sr = comp_filterbankreassign(s,tgrad,fgrad,a,cfreq);
 
167
end
 
168
 
 
169