Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@helper/time_data_worsener.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 % TIME_DATA_WORSENER introduces missing points and/or unvenly sampling time | |
2 % inside time series | |
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
4 % | |
5 % FUNCTION: time_data_worsener | |
6 % | |
7 % DESCRIPTION: TIME_DATA_WORSENER introduces missing points and/or unvenly | |
8 % sampling times inside time series | |
9 % | |
10 % CALL: [t, y] = time_data_worsener(t, y, miss_fraction, shift_fraction, shift_range); | |
11 % | |
12 % INPUTS: t vector of evenly sampled time values (in s) | |
13 % y vector of evenly sampled y values (in arb units) | |
14 % miss_fraction fraction of the total point to be skipped | |
15 % shift_fraction fraction of the total point to be shifted | |
16 % shift_range selection range for shifting the time points (in s) | |
17 % | |
18 % OUTPUTS: t vector of unevenly time values | |
19 % y vector of unevenly sampled y values | |
20 % | |
21 % EXAMPLES: [t1,y1] = time_data_worsener(t, y, 0.5, 0, [0 0]); | |
22 % [t1,y1] = time_data_worsener(t, y, 0, 0.1, [-0.05 0.05]); | |
23 % [t1,y1] = time_data_worsener(t, y, 0.1, 0.5, [0 0.01]); | |
24 % | |
25 % VERSION: $Id: time_data_worsener.m,v 1.1 2009/01/25 16:06:30 mauro Exp $ | |
26 % | |
27 % HISTORY: 25-01-2009 Hueller | |
28 % Creation | |
29 % | |
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
31 | |
32 function [t,y] = time_data_worsener(t, y, miss_fraction, shift_fraction, shift_range) | |
33 | |
34 % Initial checks | |
35 if isempty(t) || isempty(y) | |
36 error('Need to operate on non empty data vectors!') | |
37 end | |
38 | |
39 if length(y) ~= length(t) | |
40 error('t and y vector should have the same lenghts!'); | |
41 end | |
42 | |
43 if miss_fraction > 1 || miss_fraction < 0 | |
44 error('Missing points fraction f must fulfil 0 <= f <= 1!'); | |
45 end | |
46 | |
47 if shift_fraction > 1 || shift_fraction < 0 | |
48 error('Shifted points fraction f must fulfil 0 <= f <= 1!'); | |
49 end | |
50 | |
51 if length(shift_range) < 2 | |
52 error('Please input the shifting freqency range []'); | |
53 end | |
54 | |
55 %% Remove an amount of points corresponding to the fractional amount input by user | |
56 | |
57 % Calculate the orginal data vector length | |
58 N_points = length(t); | |
59 | |
60 % Calculate the number of data points to keep | |
61 N_keep = round((1 - miss_fraction) * N_points); | |
62 | |
63 % Randonmly calculate the index of the data to keep | |
64 keep_index = sort(randsample(N_points, N_keep)); | |
65 | |
66 % Extract the data from time and y vector | |
67 t = t(keep_index); | |
68 y = y(keep_index); | |
69 | |
70 %% Shift the remaining points by a random amount within the input range | |
71 N_points = length(t); | |
72 | |
73 % Calculate the number of points to shift | |
74 N_shift = round(shift_fraction * N_points); | |
75 | |
76 % Randonmly calculate the index of the data not to shift | |
77 shift_index = sort(randsample(N_points, N_shift)); | |
78 | |
79 % Randomly calculate the delay (positive or negative) and apply it | |
80 shifts = shift_range(1) + (shift_range(2) - shift_range(1))*rand(N_shift, 1); | |
81 | |
82 for kk = 1 : N_shift | |
83 t(shift_index(kk)) = t(shift_index(kk)) + shifts(kk); | |
84 end | |
85 | |
86 end |