view matlab/MATLAB-Chroma-Toolbox_2.0/normalizeFeature.m @ 42:00b6ae41efbe

Update to use qm-dsp instead of files from constant-q-cpp and bqvec. Some of the classes here (e.g. DCT) have moved to qm-dsp in the meantime.
author Chris Cannam
date Wed, 07 Oct 2015 11:46:33 +0100
parents b54ee0a0be67
children
line wrap: on
line source
function f_featureNorm = normalizeFeature(f_feature,normP, threshold)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Name: normalizeFeature
% Date of Revision: 2011-03
% Programmer: Meinard Mueller, Sebastian Ewert
%
% Description:
% - Normalizes a feature sequence according to the l^p norm
% - If the norm falls below threshold for a feature vector, then the
% normalized feature vector is set to be the unit vector.
%
% Input:
%         f_feature
%         normP
%         threshold
%
% Output:
%         f_featureNorm
%
% License:
%     This file is part of 'Chroma Toolbox'.
% 
%     'Chroma Toolbox' is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 2 of the License, or
%     (at your option) any later version.
% 
%     'Chroma Toolbox' is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with 'Chroma Toolbox'. If not, see <http://www.gnu.org/licenses/>.
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

f_featureNorm = zeros(size(f_feature));

% normalise the vectors according to the l^p norm
unit_vec = ones(1,12);
unit_vec = unit_vec/norm(unit_vec,normP);
for k=1:size(f_feature,2);
    n = norm(f_feature(:,k),normP);
    if n < threshold
        f_featureNorm(:,k) = unit_vec;
    else
        f_featureNorm(:,k) = f_feature(:,k)/n;
    end
end

end