comparison matlab/MATLAB-Chroma-Toolbox_2.0/smoothDownsampleFeature.m @ 0:b54ee0a0be67

Import MATLAB Chroma Toolbox
author Chris Cannam
date Wed, 05 Aug 2015 21:08:56 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:b54ee0a0be67
1 function [f_feature_stat,newFeatureRate] = smoothDownsampleFeature(f_feature,parameter)
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % Name: smoothDownsampleFeature
4 % Date of Revision: 2011-03
5 % Programmer: Meinard Mueller, Sebastian Ewert
6 %
7 % Description:
8 % - Temporal smoothing and downsampling of a feature sequence
9 %
10 % Remark:
11 % - parameter.featureRate specifies the input feature rate. This value is
12 % used to derive the output feature rate.
13 %
14 % Input:
15 % f_feature
16 % parameter.winLenSmooth = 1;
17 % parameter.downsampSmooth = 1;
18 % parameter.inputFeatureRate = 0;
19 %
20 % Output:
21 % f_feature
22 % newFeatureRate
23 %
24 % License:
25 % This file is part of 'Chroma Toolbox'.
26 %
27 % 'Chroma Toolbox' is free software: you can redistribute it and/or modify
28 % it under the terms of the GNU General Public License as published by
29 % the Free Software Foundation, either version 2 of the License, or
30 % (at your option) any later version.
31 %
32 % 'Chroma Toolbox' is distributed in the hope that it will be useful,
33 % but WITHOUT ANY WARRANTY; without even the implied warranty of
34 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 % GNU General Public License for more details.
36 %
37 % You should have received a copy of the GNU General Public License
38 % along with 'Chroma Toolbox'. If not, see <http://www.gnu.org/licenses/>.
39 %
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43 % Check parameters
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45
46 if nargin<2
47 parameter=[];
48 end
49 if nargin<1
50 error('Please specify input data');
51 end
52 if isfield(parameter,'winLenSmooth')==0
53 parameter.winLenSmooth = 1;
54 end
55 if isfield(parameter,'downsampSmooth')==0
56 parameter.downsampSmooth = 1;
57 end
58 if isfield(parameter,'inputFeatureRate')==0
59 parameter.inputFeatureRate = 0;
60 end
61
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 % Main program
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
66 % Temporal Smoothing
67 if (parameter.winLenSmooth ~= 1) || (parameter.downsampSmooth ~= 1)
68 winLenSmooth = parameter.winLenSmooth;
69 downsampSmooth = parameter.downsampSmooth;
70 stat_window = hanning(winLenSmooth);
71 stat_window = stat_window/sum(stat_window);
72
73 % upfirdn filters and downsamples each column of f_stat_help
74 f_feature_stat = zeros(size(f_feature));
75 f_feature_stat = (upfirdn(f_feature',stat_window,1,downsampSmooth))';
76 seg_num = size(f_feature,2);
77 stat_num = ceil(seg_num/downsampSmooth);
78 cut = floor((winLenSmooth-1)/(2*downsampSmooth));
79 f_feature_stat = f_feature_stat(:,(1+cut:stat_num+cut)); %adjust group delay
80 else
81 f_feature_stat = f_feature;
82 end
83
84 newFeatureRate = parameter.inputFeatureRate / parameter.downsampSmooth;
85
86 end
87