annotate toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirfeatures.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function r = mirfeatures(x,varargin)
Daniel@0 2 % f = mirfeatures(x) computes a large set of features from one or several
Daniel@0 3 % audio files. x can be either the name of an audio file, or the
Daniel@0 4 % 'Folder' keyword.
Daniel@0 5 % mirfeatures(...,'Stat') returns the statistics of the features instead
Daniel@0 6 % of the complete features themselves.
Daniel@0 7 % mirfeatures(...,'Segment',t) segments the audio sequence at the
Daniel@0 8 % temporal positions indicated in the array t (in s.), and analyzes
Daniel@0 9 % each segment separately.
Daniel@0 10
Daniel@0 11 %(not available yet)
Daniel@0 12 % mirfeatures(...,'Filterbank',nc) computes the analysis on each channel
Daniel@0 13 % of a filterbank decomposition.
Daniel@0 14 % Default value: nc = 5
Daniel@0 15 % mirfeatures(...,'Frame',...)
Daniel@0 16 % mirfeatures(...,'Normal')
Daniel@0 17 % mirfeatures(...,'Sampling',s)
Daniel@0 18 % miraudio options (Extract, ...)
Daniel@0 19
Daniel@0 20 [stat,nchan,segm,feat] = scanargin(varargin);
Daniel@0 21
Daniel@0 22 if isa(x,'miraudio') || isa(x,'mirdesign')
Daniel@0 23 a = miraudio(x,'Normal'); % normalize with respect to RMS energy
Daniel@0 24 % in order to consider timbre independently of
Daniel@0 25 % energy
Daniel@0 26 else
Daniel@0 27 a = miraudio('Design','Normal');
Daniel@0 28 end
Daniel@0 29
Daniel@0 30 if not(isempty(segm))
Daniel@0 31 a = mirsegment(a,segm);
Daniel@0 32 end
Daniel@0 33
Daniel@0 34
Daniel@0 35
Daniel@0 36 % DYNAMICS
Daniel@0 37 % --------
Daniel@0 38
Daniel@0 39 r.dynamics.rms = mirrms(a,'Frame');
Daniel@0 40 % Perceived dynamics: spectral slope?
Daniel@0 41
Daniel@0 42 % RHYTHM
Daniel@0 43 % ------
Daniel@0 44
Daniel@0 45 r.fluctuation = mirstruct;
Daniel@0 46 r.fluctuation.tmp.f = mirfluctuation(a,'Summary');
Daniel@0 47 r.fluctuation.peak = mirpeaks(r.fluctuation.tmp.f,'Total',1);%only one?
Daniel@0 48 r.fluctuation.centroid = mircentroid(r.fluctuation.tmp.f);
Daniel@0 49
Daniel@0 50 r.rhythm = mirstruct;
Daniel@0 51 r.rhythm.tmp.onsets = mironsets(a);
Daniel@0 52
Daniel@0 53 %r.rhythm.eventdensity = ...
Daniel@0 54
Daniel@0 55 r.rhythm.tempo = mirtempo(r.rhythm.tmp.onsets,'Frame');
Daniel@0 56 %r.rhythm.pulseclarity = mirpulseclarity(r.tmp.onsets,'Frame');
Daniel@0 57 % Should use the second output of mirtempo.
Daniel@0 58
Daniel@0 59 attacks = mironsets(r.rhythm.tmp.onsets,'Attacks');
Daniel@0 60 r.rhythm.attack.time = mirattacktime(attacks);
Daniel@0 61 r.rhythm.attack.slope = mirattackslope(attacks);
Daniel@0 62
Daniel@0 63 % TIMBRE
Daniel@0 64 % ------
Daniel@0 65
Daniel@0 66 f = mirframe(a,.05,.5);
Daniel@0 67 r.spectral = mirstruct;
Daniel@0 68 r.spectral.tmp.s = mirspectrum(f);
Daniel@0 69 %pitch = mirpitch(a,'Frame',.05,.5);
Daniel@0 70
Daniel@0 71 r.spectral.centroid = mircentroid(r.spectral.tmp.s);
Daniel@0 72 r.spectral.brightness = mirbrightness(r.spectral.tmp.s);
Daniel@0 73 r.spectral.spread = mirspread(r.spectral.tmp.s);
Daniel@0 74 r.spectral.skewness = mirskewness(r.spectral.tmp.s);
Daniel@0 75 r.spectral.kurtosis = mirkurtosis(r.spectral.tmp.s);
Daniel@0 76 r.spectral.rolloff95 = mirrolloff(r.spectral.tmp.s,95);
Daniel@0 77 r.spectral.rolloff85 = mirrolloff(r.spectral.tmp.s,85);
Daniel@0 78 r.spectral.spectentropy = mirentropy(r.spectral.tmp.s);
Daniel@0 79 r.spectral.flatness = mirflatness(r.spectral.tmp.s);
Daniel@0 80
Daniel@0 81 r.spectral.roughness = mirroughness(r.spectral.tmp.s);
Daniel@0 82 r.spectral.irregularity = mirregularity(r.spectral.tmp.s);
Daniel@0 83 %r.spectral.inharmonicity = mirinharmonicity(r.spectral.tmp.s,'f0',pitch);
Daniel@0 84
Daniel@0 85 r.spectral.mfcc = mirmfcc(r.spectral.tmp.s);
Daniel@0 86 r.spectral.dmfcc = mirmfcc(r.spectral.mfcc,'Delta');
Daniel@0 87 r.spectral.ddmfcc = mirmfcc(r.spectral.dmfcc,'Delta');
Daniel@0 88
Daniel@0 89 r.timbre.zerocross = mirzerocross(f);
Daniel@0 90 r.timbre.lowenergy = mirlowenergy(f);
Daniel@0 91 r.timbre.spectralflux = mirflux(f);
Daniel@0 92
Daniel@0 93 % PITCH
Daniel@0 94 % -----
Daniel@0 95
Daniel@0 96 r.tonal = mirstruct;
Daniel@0 97 r.tonal.tmp.chromagram = mirchromagram(a,'Frame','Wrap',0,'Pitch',0);
Daniel@0 98 r.tonal.chromagram.peak=mirpeaks(r.tonal.tmp.chromagram,'Total',1);
Daniel@0 99 r.tonal.chromagram.centroid=mircentroid(r.tonal.tmp.chromagram);
Daniel@0 100
Daniel@0 101 % TONALITY/HARMONY
Daniel@0 102 % ----------------
Daniel@0 103
Daniel@0 104 keystrengths = mirkeystrength(r.tonal.tmp.chromagram);
Daniel@0 105 [k r.tonal.keyclarity] = mirkey(keystrengths,'Total',1);
Daniel@0 106 %r.tonal.keyclarity = k{2};
Daniel@0 107 r.tonal.mode = mirmode(keystrengths);
Daniel@0 108 r.tonal.hcdf = mirhcdf(r.tonal.tmp.chromagram);
Daniel@0 109
Daniel@0 110 if stat
Daniel@0 111 r = mirstat(r);
Daniel@0 112 % SHOULD COMPUTE STAT OF CURVES FROM FRAMED_DECOMPOSED HIGH FEATURES
Daniel@0 113 end
Daniel@0 114
Daniel@0 115 if not(isa(x,'miraudio')) && not(isa(x,'mirdesign'))
Daniel@0 116 r = mireval(r,x);
Daniel@0 117 end
Daniel@0 118
Daniel@0 119
Daniel@0 120 function [stat,nchan,segm,feat] = scanargin(v)
Daniel@0 121 stat = 0;
Daniel@0 122 nchan = 1;
Daniel@0 123 segm = [];
Daniel@0 124 feat = {};
Daniel@0 125 i = 1;
Daniel@0 126 while i <= length(v)
Daniel@0 127 arg = v{i};
Daniel@0 128 if ischar(arg) && strcmpi(arg,'Filterbank')
Daniel@0 129 i = i+1;
Daniel@0 130 if i <= length(v)
Daniel@0 131 nchan = v{i};
Daniel@0 132 else
Daniel@0 133 nchan = 10;
Daniel@0 134 end
Daniel@0 135 elseif ischar(arg) && strcmpi(arg,'Stat')
Daniel@0 136 i = i+1;
Daniel@0 137 if i <= length(v)
Daniel@0 138 stat = v{i};
Daniel@0 139 else
Daniel@0 140 stat = 1;
Daniel@0 141 end
Daniel@0 142 elseif ischar(arg) && strcmpi(arg,'Segment')
Daniel@0 143 i = i+1;
Daniel@0 144 if i <= length(v)
Daniel@0 145 segm = v{i};
Daniel@0 146 else
Daniel@0 147 segm = 1;
Daniel@0 148 end
Daniel@0 149 else
Daniel@0 150 feat{end+1} = arg;
Daniel@0 151 end
Daniel@0 152 i = i+1;
Daniel@0 153 end