annotate matlab/MATLAB-Chroma-Toolbox_2.0/smoothDownsampleFeature.m @ 60:1ea2aed23d4a tip

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