Mercurial > hg > ltpda
comparison m-toolbox/classes/@tsdata/fitfs.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % FITFS estimates the sample rate of the input data. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Estimates the sample rate of the input data and detects if the | |
5 % data is evenly sampled or not. Data where any of the fluctuations in the | |
6 % time difference between subsequent samples is greater than the one due to | |
7 % finite numerical precision is detected as unevenly sampled. | |
8 % | |
9 % CALL: fs = fitfs(x) | |
10 % [fs, t0] = fitfs(x) | |
11 % [fs, t0, unevenly] = fitfs(x) | |
12 % | |
13 % INPUTS: x - sampling times vector | |
14 % | |
15 % OUTPUTS: fs - estimated samplig frequency | |
16 % t0 - estimates start time | |
17 % unevenly - signals whether the data is regularly sampled or not | |
18 % | |
19 % VERSION: $Id: fitfs.m,v 1.12 2010/05/04 11:23:59 nicolodi Exp $ | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function [fs, t0, unevenly] = fitfs(varargin) | |
24 | |
25 import utils.const.* | |
26 | |
27 % Get input vertices | |
28 xi = varargin{1}; | |
29 % Reshape x to match with linspace output | |
30 ss = size(xi); | |
31 if ss(1) > ss(2) | |
32 xi = xi.'; | |
33 end | |
34 d = diff(xi); | |
35 | |
36 % Special case of just a single number time-series | |
37 if isempty(d) | |
38 fs = 1; | |
39 t0 = 0; | |
40 unevenly = false; | |
41 return | |
42 end | |
43 | |
44 % Initial estimate | |
45 dt = mean(d); | |
46 fs = 1.0 / dt; | |
47 t0 = xi(1); | |
48 unevenly = false; | |
49 | |
50 % Strict check for unevenly sampled data. This detects as unevenly | |
51 % sampled all data where any of the fluctuations in the time | |
52 % difference between subsequent samples is greater than the one due | |
53 % to finite numerical precision | |
54 if any(abs(d - dt) > 2*eps(xi(2:end))) | |
55 utils.helper.msg(msg.PROC1, 'unevenly sampled data detected'); | |
56 unevenly = true; | |
57 | |
58 % The median is much less sensible to outliers than the mean. It is | |
59 % therefore a better estimate of the sampling frequency in case of | |
60 % unevenly sampled data | |
61 dt = median(d); | |
62 fs = 1.0 / dt; | |
63 t0 = 0; | |
64 end | |
65 | |
66 end | |
67 |