Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirroughness.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function varargout = mirroughness(x,varargin) | |
2 % r = mirroughness(x) calculates the roughness, or sensory dissonance, | |
3 % due to beating phenomenon between close frequency peaks. | |
4 % The frequency components are supposed to remain sufficiently | |
5 % constant throughout each frame of each audio file. | |
6 % r = mirroughness(...,'Contrast',c) specifies the contrast parameter | |
7 % used for peak picking (cf. mirpeaks). | |
8 % Default value: c = .01 | |
9 % [r,s] = mirroughness(x) also displays the spectrum and its peaks, used | |
10 % for the computation of roughness. | |
11 % Optional arguments: | |
12 % Method used: | |
13 % mirroughness(...,'Sethares') (default): based on the summation | |
14 % of roughness between all pairs of sines (obtained through | |
15 % spectral peak-picking). | |
16 % mirroughness(...,'Vassilakis'): variant of 'Sethares' model | |
17 % with a more complex weighting (Vassilakis, 2001, Eq. 6.23). | |
18 | |
19 meth.type = 'String'; | |
20 meth.choice = {'Sethares','Vassilakis'}; | |
21 meth.default = 'Sethares'; | |
22 option.meth = meth; | |
23 | |
24 cthr.key = 'Contrast'; | |
25 cthr.type = 'Integer'; | |
26 cthr.default = .01; | |
27 option.cthr = cthr; | |
28 | |
29 frame.key = 'Frame'; | |
30 frame.type = 'Integer'; | |
31 frame.number = 2; | |
32 frame.default = [.05 .5]; | |
33 option.frame = frame; | |
34 | |
35 specif.option = option; | |
36 specif.defaultframelength = .05; | |
37 specif.defaultframehop = .5; | |
38 | |
39 | |
40 varargout = mirfunction(@mirroughness,x,varargin,nargout,specif,@init,@main); | |
41 | |
42 | |
43 function [x type] = init(x,option) | |
44 if isamir(x,'miraudio') && not(isframed(x)) | |
45 x = mirframenow(x,option); | |
46 end | |
47 x = mirspectrum(x); | |
48 if not(haspeaks(x)) | |
49 x = mirpeaks(x,'Contrast',option.cthr); | |
50 end | |
51 type = 'mirscalar'; | |
52 | |
53 | |
54 function r = main(p,option,postoption) | |
55 if iscell(p) | |
56 p = p{1}; | |
57 end | |
58 if strcmpi(option.meth,'Sethares') || strcmpi(option.meth,'Vassilakis') | |
59 pf = get(p,'PeakPosUnit'); | |
60 pv = get(p,'PeakVal'); | |
61 rg = cell(1,length(pf)); | |
62 for h = 1:length(pf) | |
63 rg{h} = cell(1,length(pf{h})); | |
64 for i = 1:length(pf{h}) | |
65 pfi = pf{h}{i}; | |
66 pvi = pv{h}{i}; | |
67 rg{h}{i} = zeros(1,length(pfi)); | |
68 for k = 1:size(pfi,3) | |
69 for j = 1:size(pfi,2) | |
70 pfj = pfi{1,j,k}; | |
71 pvj = pvi{1,j,k}; | |
72 f1 = repmat(pfj,[1 length(pfj)]); | |
73 f2 = repmat(pfj',[length(pfj) 1]); | |
74 v1 = repmat(pvj,[1 length(pvj)]); | |
75 v2 = repmat(pvj',[length(pvj) 1]); | |
76 rj = plomp(f1,f2); | |
77 if strcmpi(option.meth,'Sethares') | |
78 rj = v1.*v2.*rj; | |
79 elseif strcmpi(option.meth,'Vassilakis') | |
80 rj = (v1.*v2).^.1.*.5.*(2*v2./(v1+v2)).^3.11.*rj; | |
81 end | |
82 rg{h}{i}(1,j,k) = sum(sum(rj)); | |
83 end | |
84 end | |
85 end | |
86 end | |
87 else | |
88 end | |
89 r = mirscalar(p,'Data',rg,'Title','Roughness'); | |
90 r = {r,p}; | |
91 | |
92 | |
93 function pd = plomp(f1, f2) | |
94 % returns the dissonance of two pure tones at frequencies f1 & f2 Hz | |
95 % according to the Plomp-Levelt curve (see Sethares) | |
96 b1 = 3.51; | |
97 b2 = 5.75; | |
98 xstar = .24; | |
99 s1 = .0207; | |
100 s2 = 18.96; | |
101 s = tril(xstar ./ (s1 * min(f1,f2) + s2 )); | |
102 pd = exp(-b1*s.*abs(f2-f1)) - exp(-b2*s.*abs(f2-f1)); | |
103 return |