To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _beattracker / getperiod.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.17 KB)
| 1 |
function [period,rcf,period2] = getperiod(acf,wv,timesig,pmax,pmin,lowest) |
|---|---|
| 2 |
|
| 3 |
|
| 4 |
% using for loop approach to extract beat period |
| 5 |
|
| 6 |
pmax = round(pmax); |
| 7 |
pmin = round(pmin); |
| 8 |
|
| 9 |
rcf = zeros(1,pmax); |
| 10 |
|
| 11 |
|
| 12 |
if(~timesig) % timesig unknown, must be general state |
| 13 |
numelem = 4; |
| 14 |
|
| 15 |
for i=pmin:pmax-1, % maximum beat period |
| 16 |
for a=1:numelem, % number of comb elements |
| 17 |
for b=1-a:a-1, % gs using normalization of comb elements |
| 18 |
rcf(i) = rcf(i) + (acf(a*i+b)*wv(i))/(2*a-1); |
| 19 |
end |
| 20 |
end |
| 21 |
end |
| 22 |
|
| 23 |
else |
| 24 |
numelem = timesig; % timesig known must be context dependent state |
| 25 |
|
| 26 |
for i=pmin:pmax-1, % maximum beat period |
| 27 |
for a=1:numelem, % number of comb elements |
| 28 |
for b=1-a:a-1, % cds not normalizing comb elements |
| 29 |
rcf(i) = rcf(i) + acf(a*i+b)*wv(i); |
| 30 |
end |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
end |
| 35 |
|
| 36 |
|
| 37 |
[val, period] = max(rcf); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
period = refineperiod(period,acf,timesig); |
| 43 |
|
| 44 |
|
| 45 |
while(period<lowest) |
| 46 |
period = period*2; |
| 47 |
end |
| 48 |
%period |
| 49 |
|
| 50 |
if (~sum(abs(wv))) % i.e. using cds_wv before initialised |
| 51 |
period = 0; |
| 52 |
end |
| 53 |
|
| 54 |
% not important... just here to prevent an error in the number of outputs |
| 55 |
period2 = period*2; |
| 56 |
%figure(1); plot(rcf); pause |