Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/mirzerocross.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 = mirzerocross(orig,varargin) | |
2 % mirzeroscross(x) computes the sign-changes rate along the signal x, | |
3 % i.e., how many time the waveform crosses the X-axis. When applied on | |
4 % an audio waveform, gives a notion of noise. | |
5 % Optional argument: | |
6 % mirzerocross(...,'Per',p) precises the temporal reference for the | |
7 % rate computation. | |
8 % Possible values: | |
9 % p = 'Second': number of sign-changes per second (Default). | |
10 % p = 'Sample': number of sign-changes divided by the total | |
11 % number of samples. | |
12 % The 'Second' option returns a result equal to the one returned | |
13 % by the 'Sample' option multiplied by the sampling rate. | |
14 % mirzerocross(...,'Dir',d) precises the definition of sign change. | |
15 % Possible values: | |
16 % d = 'One': number of sign-changes from negative to positive | |
17 % only (or, equivalently, from positive to negative only). | |
18 % (Default) | |
19 % d = 'Both': number of sign-changes in both ways. | |
20 % The 'Both' option returns a result equal to twice the one | |
21 % returned by the 'One' option. | |
22 | |
23 | |
24 per.key = 'Per'; | |
25 per.type = 'String'; | |
26 per.choice = {'Second','Sample'}; | |
27 per.default = 'Second'; | |
28 option.per = per; | |
29 | |
30 dir.key = 'Dir'; | |
31 dir.type = 'String'; | |
32 dir.choice = {'One','Both'}; | |
33 dir.default = 'One'; | |
34 option.dir = dir; | |
35 | |
36 specif.option = option; | |
37 | |
38 varargout = mirfunction(@mirzerocross,orig,varargin,nargout,specif,@init,@main); | |
39 | |
40 | |
41 function [x type] = init(x,option) | |
42 if not(isamir(x,'mirdata')) | |
43 x = miraudio(x); | |
44 end | |
45 type = 'mirscalar'; | |
46 | |
47 | |
48 function z = main(a,option,postoption) | |
49 if iscell(a) | |
50 a = a{1}; | |
51 end | |
52 d = get(a,'Data'); | |
53 f = get(a,'Sampling'); | |
54 v = cell(1,length(d)); | |
55 for h = 1:length(d) | |
56 v{h} = cell(1,length(d{h})); | |
57 for i = 1:length(d{h}) | |
58 di = d{h}{i}; | |
59 nc = size(di,2); | |
60 nf = size(di,3); | |
61 nl = size(di,1); | |
62 zc = sum( di(2:end,:,:).*di(1:(end-1),:,:) < 0 ) /nl; | |
63 if strcmp(option.per,'Second') | |
64 zc = zc*f{h}; | |
65 end | |
66 if strcmp(option.dir,'One') | |
67 zc = zc/2; | |
68 end | |
69 v{h}{i} = zc; | |
70 end | |
71 end | |
72 z = mirscalar(a,'Data',v,'Title','Zero-crossing rate'); |